[dmd-concurrency] Shutdown protocol

Steve Schveighoffer schveiguy at yahoo.com
Thu Jan 21 12:35:28 PST 2010


----- Original Message ----

> From: Michel Fortin <michel.fortin at michelf.com>
> 
> 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: 
> .
> 
> 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.
> 

Maybe in the event that the threads exit in the order you join them, but the end result is the main thread resumes immediately after the last thread exits.  Calling join on a finished thread does not require any context switching or messages, it simply returns immediately with the exit code.

In any case, I don't think the primitives are there to support this in all OSes.  Not that it can't be an optimization point, but at least it will work the way I expected with a loop instead of joinAll.

-Steve



      


More information about the dmd-concurrency mailing list