There is a trade-off of efficiency when using semaphores,
depending on how long a lock is held before you get it:
Semaphores might waste CPU time by
switching to another process if they cannot get the lock, because
if the lock had been free, the switch would have been unnecessary.
Semaphores might save CPU time by switching to another
process if they cannot get the lock, because one process can do
useful work while the process is waiting for the lock.
If the lock will be held for a long time (compared to a context
switch), switching is preferable; but if held briefly, spinning
might be better.