Wednesday, April 29, 2020

Thread Synchronization

Thread synchronization is the concurrent execution of two or more threads that share critical resources. Threads should be synchronized to avoid critical resource becoming conflict. A conflict may arise when parallel-running threads attempt to modify a common variable at the same time. 

In other words it is defined as a mechanism which ensures that two or more concurrent processes or threads do not simultaneously execute some particular program segment known as a critical section. Access to critical section is controlled by using synchronization techniques. 

Consider the following example: three threads - A, B, and C - are executed concurrently and need to access a critical resource, Z. To avoid conflicts when accessing Z, threads A, B, and C must be synchronized. Thus, when A accesses Z, and B also tries to access Z, B’s access of Z must be avoided with security measures until A finishes its operation and comes out of Z. 

In pthreads the following 4 types of synchronization methods are available
  • Mutex Locks
  • Condition variables
  • Read-Write Locks
  • Semaphores
I will deal with each of these synchronization techniques in separate posts.

No comments:

Post a Comment