Pre-emption can occur if the code exceeds the time slice intended for it, then how do we ensure code length/execution time in the spinlock?

StackOverflow https://stackoverflow.com/questions/23370574

Question

--> Re-editing my question. I thought to picture my understanding. Here is the picture. Please correct me here. By task, I mean process only. A picture is worth a thousand words.

enter image description here

enter image description here

What will happen in the multi-processor, if the third process wants to acquire the lock. Since, it is two processor. The third processor may try to acquire the lock on CPU A since CPU B is busy polling. This can lead to a problem. Is my understanding correct? So, while using spin lock - one should ensure that the number of process contending for the critical region should not be greater than the number of CPU's available in the system? Also, if my system is uniprocessor, I shouldn't use spin lock at all. As it is compiled off? Is my understanding correct? We do not use sleep inside spinlocks is that because we don't want the code to do pre-empted during sleep when actually inside the spinlock () - which disables pre-emption. But pre-emption can occur if the code execution time exceeds the time slice intended for it. Thus, my question is basic - should we use a short length of code inside critical region? Because a long execution code can cause also pre-emption as the sleep would cause?

Was it helpful?

Solution

The confusion is because you looking everything from "process context" only and totally forget Intr context, premption

http://www.makelinux.net/ldd3/chp-5-sect

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