Presentation is loading. Please wait.

Presentation is loading. Please wait.

Thread Synchronization

Similar presentations


Presentation on theme: "Thread Synchronization"— Presentation transcript:

1 Thread Synchronization

2 Consistency Problems Multiple threads share the same memory:
Must make sure that each thread sees a consistent view of its data. No consistency problem exists: Each thread uses variables that other threads don't read or modify If a variable is read-only, because many threads may read its value at the same time. Consistency problem: One thread can modify a variable that other threads can read or modify Need to synchronize the threads to ensure that they don't use an invalid value when accessing the variable's memory contents. If one thread modifies a variable, other threads can potentially see inconsistencies when reading the value of the variable

3 Consistency Problems Threads have to use a lock that will allow only one thread to access the variable at a time.

4 Consistency Problems

5 Consistency Problems Need to synchronize >=2 threads that might try to modify the same variable at the same time. For example, in the case in which we need to increment a variable: Read the memory location into a register. Increment the value in the register. Write the new value back to the memory location.

6 Consistency Problems


Download ppt "Thread Synchronization"

Similar presentations


Ads by Google