Thursday 25 September 2014

Critical Section

In concurrent programming, Critical section is a set of statements that should be run exclusively . When multiple processes that shares same data are run simultaneously there are chances for the data to be inconsistent. So an operating system is designed in such a way that only one of the processes among them is allowed to access the shared data at a time. A critical section terminates in a fixed time, so a process or task must wait for that fixed time to enter its critical section.
Critical section is used when multi threaded programming need to manipulate a shared data without creating further threads conflicting the data. It also ensures that a shared device is accessed only by a single process at a time.
In single processor systems critical section can be implemented by disabling interrupts while entering the critical section, prevent system calls causing context switches while inside the critical section and restoring the interrupts while exit. With this implementation, any thread entering critical section any where in the system will prevent other thread trying to execute its critical section. Thus CPU can’t be accessed by any other process until the running process exits the CPU.
So far there are many algorithms that came up with solving the issues regarding the execution of critical section. The solutions for critical section is a wide area to discuss...