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 ?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top