Critical Section and it’s Problems

What is Critical Section?

It is a code segment that accesses shared resources and should execute as an atomic action.

Critical Section comes under the topic Process Synchronization.

Critical Section

It is a code segment that accesses shared resources and should execute as an atomic action. If the number of processes accessing the same code segment is greater than one, then that segment is known as critical section. 

If a process is in a critical section, all different processes that access the shared changeable resources are denied entry from critical section. In a cluster of co-operating processes at a particular time, solely one process can execute in critical section. Other processes will have to wait for the process in critical section to complete its execution.

Critical Section

Different codes or processes could carry with it an equivalent variable or different resources that require to be scan or written however whose results rely upon the order within which the actions occur. For instance, if a variable ‘x’ is to be scanned by method A, and method B should write to an equivalent variable ‘x’ at the same time, method A would possibly get either the previous or new value of ‘x’.

In cases like these, a critical section is very important. In the aforementioned case, if A must browse the updated value of ‘x’, executing process A and process B at an equivalent time might not provide needed results. To stop this, variable ‘x’ is secured by a critical section. First, B gets the allowance to the section. Once B completes writing the value, A gets the access to the critical section and variable ‘x’ may be browsed.

Critical Section Problem

To allow and deny the processes from moving into the critical section, it proves troublesome for the OS .

The result can not be foreseen if a thread is attempting to alter the data of shared variable at the same time as different thread is trying to retrieve the value.

Let’s take n number of processes {R0, R1, …. Rn-1}.

Every process has critical section segment of code.

  • Process may be updating, altering common values , file writing.
  • When a single process is in critical section, no different process should be in its critical section.

Leave a comment

Design a site like this with WordPress.com
Get started