edited by
2,588 views
4 4 votes

Can a process be preempted while it is in a critical section?

If yes, then how does the critical section or synchronisation mechanism concept provide solution for 'Data inconsistency'?

If no, then how the gate2013 problem on critical section is solved.( LInks are given below)

1. for gateoverflow answer: https://gateoverflow.in/1545/gate2013-34

2. for video explanation of the solution: https://www.youtube.com/watch?v=jDUJsCFNI0E

In video explanation instead of preemption sir has used context switch. How preemption is different from context switch?

1 Answer

3 3 votes

No, a process in Critical Section can not be preempted. Best example to understand this is Priority Inversion:

https://en.m.wikipedia.org/wiki/Priority_inversion

That GATE 2013 problem is based on counting semaphore that can allow upto two processes at a same time in the Critical Section. There is no preemption there. 

I haven't watched the video but I think you are not clear about the meaning of preemption and context switch.

Preemption: A process under execution(not in Critical Section) is preempted by a higher priority process, i.e., now the previous process is in blocked/waiting queue and the resources it had are now free to be used by the new higher priority process. Preemption is about getting hold of the processor to execute. Best example of preemption is any preemptive scheduling algorithm, like Round Robin.

https://en.m.wikipedia.org/wiki/Preemption_(computing)

Context Switch: Here context means information of a process, stored in Process Control Block of a process. Context Switch happens whenever a process under execution is paused to execute another process. This is done by storing info about the process so that when the process is loaded again, it is in the same state. Read "Steps" section in the below link:

https://en.m.wikipedia.org/wiki/Context_switch

I also suggest you to read about Spinlock if you don't know about it yet. It will deepen the understanding.

Position:
Show:

Related questions

0 0 votes
0 0 answers
2.2k
2.2k views
amitqy asked Nov 21, 2018
2,158 views
5 5 votes
1 1 answer
2.2k
2.2k views
Akash Kumar Roy asked Mar 27, 2018
2,159 views
My question is little different.Each Process Pi, i = 1....9 is coded as followsrepeat P(mutex) {Critical section} V(mutex)foreverThe code for P10 is identical ex...
0 0 votes
0 0 answers
604
604 views
jatinmittal199510 asked Jan 15, 2017
604 views
Does Mutex provide Bounded Waiting solution ? (since it can lead to deadlock state, and I studied somewhere that if there is deadlock then we cannot assure Bounded Wait...
6 6 votes
5 answers 5 answers
2.3k
2.3k views
Bikram asked Sep 3, 2016
2,300 views
Each process $P_i$, where $i= 1$ to $9$ is coded as follows repeat P (mutex) {critical section } V (mutex) foreverThe code for $P_{10}$ is identical except that it uses ...