I read an answer on this site says the spin-lock reduce the overhead with context switches, and after that I read an textbook statement related to this:
Spin-lock makes a busy waiting program not be interrupted.
My question is on the title.
Since the book uses while-loop to indicate the implementation of the spin part of a spin-lock, the following is my reasoning trying to explain myself with this consideration.
This sounds like if there is a program with a busy waiting while loop then all the others program(processes) won't be executed forever, but won't this make a multiprogramming environment broken down, since the others processes can no longer to be executed after certain time interval has past? But I remember that the OS will prevent any process from dominate the CPU forever?
Or this is generally true in most architecture so it's not recommended since the degree of multiprogramming decrease, or one has to know precisely how long it will stop? Sorry for vague question but what I typed is exactly the same as the book states.
For more details about my confusion: I think for a given while loop
while (this == true);
is nothing more than the expended version
if (this == true);
if (this == true);
if (this == true);
...
...
if (this == true); // (*)
...
...
if (this == true);
...
So why it won't be interrupted at some (*)
step above, for some reason like the time interval for the process is ended and another process is chosen from the ready queue?
while (this == true);
express a spin (busy waiting), but not a spinlock, which additionally provides a protection from switching a process. – Rockhampton