Does a synchronization yield on waiting thread?

Prudence via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 12 19:48:05 PDT 2015


It would seem to be the logical thing to do?

That is, suppose two threads are sharing a resource. Thread A has 
it locked. B is "waiting". Is B in a loop burning cycles running 
in the background(regardless of thread.sleep, which only 
alleviates the problem) or does it yield completely and somehow 
inform the lock to resume it when A has unlocked the resources?

The first one burns cycles and can have timing problems. I.e., 
What if A locks and unlocks at the same rate that B checks? (I 
suppose a random sleep time would help with this) (

"Yielding", OTOH, has B burn no cycles waiting in a loop. This 
can lead to optimization and prioritization and all that(after an 
unlock, all the threads waiting can be called, but in what order).

Obviously yielding is more complex and requires the threads kept 
track of(an array for each lock/unlock pair) but far more 
efficient.

I'm hoping D does this, but not holding my breath.





More information about the Digitalmars-d-learn mailing list