confusion about locking [ Pls help ]

Er Krishna erkrishna at
Sat Apr 11 10:12:48 EDT 2015

Hi All,

Can somebody help me here to understand  following basic scenario about
locking. Sorry if I am wrong in putting my points in correct manner.

1. Can we take semaphore (binary semaphore or mutex) if the critical
section data is shared across two  different threads/processes which are
running on two different processors simultaneously/parallely ? I know
spin_lock() can handle this scenario, but I was trying to understand can
semaphore also handle this scenario, assuming there is no interrupt and
only process context is there ? I think yes.  Pls confirm me on this and if
not then why not ? If any pross and cons are involved pls tell that also.

2. If the critical section data is shared across process and interrupt (
consider this scenario on uniprocessor machine  and I have not taken
local_irq_save() or any spin_lock_irqsave )  and in the currently executing
process  critical section is protected by  preempt_disable()  and suddenly
an interrupt occurs which also wants to access same critical section data,
so what will happen ? Will in  this case Interrupt handler  acquire the
critical section data and corrupt the kernel or it will sleep and corrupt
the kernel or it will keep doing busy waiting ? I think interrupt handler
will keep doing busy waiting and machine will stuck, kind of deadlock. Pls
confirm me.

3. Does Preemption gets disable ( on local processor ) in case of binary
semaphore or mutex ? I think no. Pls confirm. Second,  Lets say critical
section is shared across process and interrupt and it is locked by
semaphore (binary semaphore or mutex) in process context on  uniprocessor
machine.  If Interrupt comes then what will happen ? Will it preempt the
process and acquire the critical section of data and corrupt it or
interrupt will go into sleep mode and machine can  crash/stuck. Pls explain.

Best Regards,
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Kernelnewbies mailing list