12 Dec 2019

  • December 12, 2019
  • Amitraj
Process Synchronization

A co-operative process is the one which can affect the execution of other process or can be affected by the execution of other process. Such processes need to be synchronized so that their order of execution can be guaranteed.

The procedure involved in preserving the appropriate order of execution of co-operative processes is known as Process Synchronization. There are various synchronization mechanisms that are used to synchronize the processes.



Race Condition

A Race Condition typically occurs when two or more threads try to read, write and possibly make the decisions based on the memory that they are accessing concurrently.



Critical Section Problem

-> when more then one processes access a same code segment that segment is known as critical section. critical section contain shared variables or resources which are needs to be synchronized to maintain consistency of data variable.

-> In simple terms a critical section is group of instruction / statements or region of code that need to be executed Atomically, such as accessing a resource (file,input or output port, global data etc).

-> In concurrent programming, if one thread tries to change the value of shared data at the same time as another thread tries to read the value (i.e. data race across threads), the result is unpredictable.


-> A diagram of critical section as follows:-




-> Any solution to a critical section problem must satisfy 3 conditions:-


1. Mutual exclusion -

 If a process is executing in its critical section, then no other process is allowed to execute in the critical section.


2. Progress -

If no process is executing in the critical section and other processes are waiting outside the critical section, then only those processes that are not executing in the reminder section can paticipate in deciding which will enter in the critical section next, and the selection can not be postponed indefinietly.


3. Bounded-waiting -

 A Bounded must exist on the no. of times that other processes are allowed to enter there critical sections after a process has made a request to enter its critical section and before that request is granted.



Translate

Popular Posts