Question

In an operating system subject i'm taking this semester we were asked this question

what are the techniques that can be used to protect critical sections ??

i tried searching online but couldn't find anything

could anyone please briefly explain critical sections and what techniques to protect them ?

Was it helpful?

Solution

First of all critical section applies only to parallel execution, and it is a piece of code that cannot be executed by more than one thread / process at given time. It occurs when two or more threads or processes want to write into the same location at once, which potentially can cause incorrect state of the data or deadlock.

Even so innocent looking piece of code as i += 1 has to be protected in parallel world -- you have to remember that execution of thread or process can be suspended at any time by OS.

The basic mechanism of synchronization are mutexes and monitors.

With semaphores one can limit access to resources.

OTHER TIPS

a) A process must first declare its intention to enter the critical section by raising a flag.

b) Next, the critical section is entered and upon leaving, the flag is lowered.

c) If the process is suspended after raising the flag but before it able to enter the critical section, the other process will see the raised flag and not enter until the flag is lowered.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top