[dmd-concurrency] Shutdown protocol

Steve Schveighoffer schveiguy at yahoo.com
Thu Jan 21 12:47:36 PST 2010


----- Original Message ----

> From: Andrei Alexandrescu <andrei at erdani.com>
>
> Sean Kelly wrote:
> > On Jan 21, 2010, at 12:35 PM, Steve Schveighoffer wrote:
> >> 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.
> > 
> > Yeah exactly.  Joining in a loop shouldn't be noticeably slower than joining 
> all in parallel.
> 
> Not if they want to close sockets gracefully or best-effort-gracefully as in 
> your destructor example. Actually your own destructor example ruins your point 
> because it has a relatively high latency!!!

Yeah, but joining one thread does not mean "Hey OS, only run this one thread until it exits."  All the other threads can shut down in parallel (as they will because they just got the shutdown message prior to the join loop).  Then once your really long thread exits, the rest of the joins are relatively instantaneous.  In other words, the effect of the loop waits until the thread that takes the longest terminates.  It's the same effect as an OS primitive that does the same, except as Michel pointed out, the scheduler may pull some tricks to make it insignificantly faster.

-Steve



      


More information about the dmd-concurrency mailing list