Preview

Liham Pangaplikasyon

Powerful Essays
Open Document
Open Document
6908 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Liham Pangaplikasyon
Chapter I
1. Race Condition
Race Condition occurs when two threads access a shared variable at the same time. The first thread reads the variable, and the second thread reads the same value from the variable. Then the first thread and second thread perform their operations on the value, and they race to see which thread can write the value last to the shared variable. The value of the thread that writes its value last is preserved, because the thread is writing over the value that the previous thread wrote.

Example:

for ( int i = 0; i < 10000000; i++ ) { x = x + 1; }

If you had 5 threads executing this code at once, the value of x WOULD NOT end up being 50,000,000. It would in fact vary with each run.
This is because, in order for each thread to increment the value of x, they have to do the following: (simplified, obviously)

Retrieve the value of x
Add 1 to the value of x
Store the value of x

Any thread can be at any step in this process at any time, and they can step on each other when a shared resource is involved. The state of x can be changed by another thread during the time between x is being read and when it is written back.
Let's say a thread retrieves the value of x, but hasn't stored it yet. Another thread can also retrieve the samevalue of x (because no thread has changed it yet) and then they would both be storing the samevalue (x+1) back in x!

Example:
Thread 1: reads x, value is 7
Thread 1: add 1 to x, value is now 8
Thread 2: reads x, value is 7
Thread 1: stores 8 in x
Thread 2: adds 1 to x, value is now 8
Thread 2: stores 8 in x

Race conditions can be avoided by employing some sort of locking mechanism before the code that accesses the shared resource:

for ( int i = 0; i < 10000000; i++ )
{
//lock x x = x + 1; //unlock x
}

Here, the answer comes out as 50,000,000 every time.

END OF CHAPTER I

Chapter II
2. Virtual

You May Also Find These Documents Helpful

  • Good Essays

    Among them the first approach was proposed in 1984 by Chandy and Lamport, to build a possible global state of a distributed system [20]. The goal ofthis protocol is to build a consistent distributed snapshot of the distributed system. A distributed snapshot is a collection of process checkpoints (one per process), and a collection of in-flight messages (an ordered list of messages for each point to point channel). The protocol assumes ordered loss-less communication channel; for a given application, messages can be sent or received after or before a process took its checkpoint. A message from process p to process q that is sent by the application after the checkpoint of process p but received before process q checkpointed is said to be an orphan message. Orphan messages must be avoided by the protocol, because they are going to be re-generated by the application, if it were to restart in that snapshot. Similarly, a message from process p to process q that is sent by the application before the checkpoint of process p but received after the checkpoint of process q is said to be missing. That message must belong to the list of messages in channel p to q, or the snapshot is inconsistent. A snapshot that includes no orphan message, and for which all the saved channel messages are missing messages is consistent, since the application can be started from that state and pursue its computation…

    • 1211 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    Nt1310 Unit 1 Study Guide

    • 378 Words
    • 2 Pages

    Multiple threads can interfere with each other when sharing hardware resources such as caches or translation lookaside buffers (TLBs). As a result, execution times of a single thread are not improved but can be degraded, even when only one thread is executing, due to lower frequencies or additional pipeline stages that are necessary to accommodate thread-switching hardware.…

    • 378 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    En1320 Unit 1 Research Paper 1

    • 27742 Words
    • 111 Pages

    The code in Figure 2-8 shows that even a simple operation, such as the addition of two…

    • 27742 Words
    • 111 Pages
    Powerful Essays
  • Good Essays

    Arrays store items that have the same type of data type like a group of employees’ names and social security numbers for a team of 2000 personal. Pointer is a variable that greatly extends the power and flexibility of a program, each memory location that is used to store data value has an address. The address provides the means for a PC hardware to reference a particular data item.…

    • 485 Words
    • 2 Pages
    Good Essays
  • Better Essays

    ops final

    • 1186 Words
    • 10 Pages

    The current Value Stream Map also shows where waiting occurs and helps determine where waiting…

    • 1186 Words
    • 10 Pages
    Better Essays
  • Satisfactory Essays

    2. What is the role of the contentionscope for pthreads? How does it affect the execution…

    • 299 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Sharing allows several processes to access the same portion of main memory (Stallings, 2012). When there are a number of processes executing the same program it is beneficial to allow each process to access the same copy of the program rather than have its own separate copy (Stallings, 2012,). The memory management system must therefore…

    • 573 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 3 Os

    • 1341 Words
    • 6 Pages

    +• Scheduling: Any processor may perform scheduling, which complicates the task of enforcing a scheduling policy and assuring that corruption of the scheduler data structures is avoided. If kernel-level multithreading is used, then the opportunity exists to schedule multiple threads from the same process simultaneously on multiple processors.…

    • 1341 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    This mean the series of the communication cycle can be interpreted or explain when other people are communicating and they can adjust their own order of performance in order for them to communicate efficiently. Within the one to one communication Argyle involves different code in which it can be translated and it will be understood by the message sent between the one to one…

    • 65 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Topology Diagram Topology

    • 349 Words
    • 2 Pages

    Information is passed from one computer to another in either clock-wise direction or counter clock-wise direction and after receiving the information, the receiver must send the “acknowledgement” message (ACK message) back to the sender to complete the transmission.…

    • 349 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    S12 Midterm Sol

    • 2644 Words
    • 19 Pages

    Almost ALL registers are stored in a trap frame when a trap occurs (interrupt/syscall/exception), but only a subset are backed up when a thread context switch occurs. So (for example) s1 would be in both, but temp register t0 would only be in the trapframe. The thread context also has threadspecific information, such as…

    • 2644 Words
    • 19 Pages
    Powerful Essays
  • Powerful Essays

    What value is assigned to the String variable strSecond when the following code is executes?…

    • 2759 Words
    • 44 Pages
    Powerful Essays
  • Good Essays

    11. Using a floating-point value as a control variable in a loop, but failing to account for the effects of floating-point precision, can cause a loop to execute much differently than expected.…

    • 719 Words
    • 3 Pages
    Good Essays
  • Good Essays

    This means that the first object is not replaced before the second is selected. It therefore…

    • 2852 Words
    • 12 Pages
    Good Essays
  • Good Essays

    * Consistent: The system can coordinate actions by multiple components often in the presence of concurrency and failure. This underlies the ability of a distributed system to act like a non-distributed system.…

    • 833 Words
    • 4 Pages
    Good Essays

Related Topics