[dmd-concurrency] Shutdown protocol
Steve Schveighoffer
schveiguy at yahoo.com
Thu Jan 21 12:26:05 PST 2010
----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
>
> Steve Schveighoffer wrote:
> >> From: Andrei Alexandrescu
> >> 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.
>
> What I mean is the following. Before joining threads and terminate app, you have
> a means to tell them it's about time to finish. So the sequence looks like this:
>
> broadcastShutdown();
> joinAll();
>
> Now say you have 24 threads with a latency of 100ms each. If you join them
> serially, it takes 2.4 seconds. If you join them simultaneously, it ideally
> takes 100ms.
If a thread has exited, it takes probably a few hundred cycles to return, probably not 100ms. If it has not exited, no amount of parallelism is going to save you from waiting for the thread to exit.
A join sends no messages or anything, it simply waits until the thread has exited and deposited it's return code, then returns the return code. While you are joining a slow-to-exit thread, all your other threads have exited, so in essence the parallelism occurs because the broadcast of the shutdown gets all the threads ready to be joined. I don't see any benefit to joinAll (except to avoid having to write a loop).
-Steve
More information about the dmd-concurrency
mailing list