written 6.9 years ago by | • modified 6.7 years ago |
Subject: Operating System
Topic: PROCESS MANAGEMENT
Difficulty: Hard
written 6.9 years ago by | • modified 6.7 years ago |
Subject: Operating System
Topic: PROCESS MANAGEMENT
Difficulty: Hard
written 6.7 years ago by | modified 6.6 years ago by |
Critical Section A Critical Section is a code segment that accesses shared variables and has to be executed as an atomic action. It means that in a group of cooperating processes, at a given point of time, only one process must be executing its critical section. If any other process also wants to execute its critical section, it must wait until the first one finishes.
Structure of process
{
Do
.
.
.
}
while (TRUE)
A solution to the critical-section problem must satisfy the following three requirements:
Mutual Exclusion: If process Pi is executing in its critical section, then no other processes can be executing in their critical sections.
Progress: If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely.
Bounded Waiting: A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted.
Race Condition
The situation where several processes access – and manipulate shared data concurrently. The final value of the shared data depends upon which process finishes last. To prevent race conditions, concurrent processes must be synchronized.Data consistency requires that only one processes should update the value of a data item at any time. Race condition occurs when more than one process writes data item so that final result is dependent on the order of execution of instructions in the multiple processes.
This is ensured through the notion of a critical section. A critical section for data item d is a section of code, which cannot be executed concurrently with itself or with other critical sections for data item d.
Consider a system of n processes (P0, P1,…, Pn-1), each process has a segment of code called a critical section, in which the proceses may be changing common variables, updating a table, writing a file, and so on. The important feature of the system is that, when one process is executing in its critical section, no other process is to be allowed to execute in its critical section. Thus the execution of critical sections by the processes is mutually exclusive in time.