[dmd-concurrency] Shutdown protocol

Michel Fortin michel.fortin at michelf.com
Thu Jan 21 12:26:33 PST 2010


Le 2010-01-21 à 14:59, Steve Schveighoffer a écrit :

>>> What does joinAll do?  I admit I am not too familiar with your proposed API.
>> 
>> The idea is to join on all threads in parallel. Otherwise, if you have N 
>> threads, the Nth will become aware you plan to shutdown only after all 
>> others have already finished.
> 
> Hm... in all other threading libraries I used, calling join did not change the state of the thread at all, it just waited for the thread to return.  So in those libraries, "joining threads in parallel" had no effect.

If the thread calling join has a higher priority, it might bump the priority of the joined threads to avoid a priority inversion. See: <http://en.wikipedia.org/wiki/Priority_inversion>.

If all threads have the same priority, the effect joinAll might have is avoid a few context switches that would be otherwise required advance the loop. It probably won't be noticeable unless you're very tight on processing time.

But as a general rule you can say that joinAll is better since it gives more information to the scheduler about your thread dependencies.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list