
20 Sep
2006
20 Sep
'06
11:25 a.m.
Anthony Williams wrote:
Yes, there's overhead in a semaphore wait, but it's not pointless --- it allows the OS to schedule the threads appropriately. If you have contention, both threads have to do the same thing, otherwise you've added an implicit bias.
Bias in favor of the currently running thread is good as it improves performance.
We could just do a spin-wait if we want really-fast locks and unlocks ---
Spin-wait can also be slower; it just burns CPU instead of giving it to a thread that could have done something with it. The performance of the individual thread may look like an improvement, but the total time for the task can still increase.