[dmd-concurrency] Shutdown protocol
Andrei Alexandrescu
andrei at erdani.com
Wed Jan 20 11:29:26 PST 2010
Michel Fortin wrote:
> Le 2010-01-20 à 12:20, Andrei Alexandrescu a écrit :
>
>> I like this. All - any related thoughts?
>>
>> Truth be told we can fix the example by changing main:
>>
>> wait(spawn(©("in1", "out1")), spawn(©("in2", "out2")));
>>
>> which I think is entirely fair.
>
> As I said, (although I used 'join' instead of 'wait' to say it), using 'wait' this way will leave the writer thread alive while the second copy finishes. It's not too bad with only two copies, but if your program is long-lived and is making a lot of copy threads while it runs you'll end up with a lot of forgotten do-nothing writer threads until the program finishes.
Oh, rats. I missed your point :o).
I agree that in general, the clean way to finish work is to have threads
use a protocol for termination. OOB communication helps there as well -
the nice thing about Shutdown is that it's not "special", it's just an
instance of a more general communication mechanism.
Speaking of integration with socket communication: we need to integrate
that as well. If a socket is waiting and shutdown occurs, any socket
function will throw Shutdown (or possibly a different exception).
Andrei
More information about the dmd-concurrency
mailing list