[dmd-concurrency] Shutdown protocol

Andrei Alexandrescu andrei at erdani.com
Wed Jan 20 15:54:32 PST 2010


Sean Kelly wrote:
> On Jan 20, 2010, at 11:26 AM, Andrei Alexandrescu wrote:
>> I don't think so. When the two instances of the copy threads finish reading and sending messages to their writers, they return. As a consequence, wait returns. As a consequence, main finishes.
>>
>> At this critical point, we have the following situation:
>>
>> (a) main has finished, therefore the shutdown mode is in effect
>>
>> (b) There are a number of messages in flight containing buffers waiting to be written in the two files.
>>
>> The important thing to do is to NOT throw shutdown as long as calls to receive() would not block.
> 
> That sounds like a horrible race problem.


Not at all. On the contrary, it's the stark opposite of a race:

* Readers only finish after they have sent all messages they had to send.

* Application doesn't shutdown until all sent messages have been acted upon.

It's actually remarkably clean how the two-files copy program shuts down.

I'd agree with you it would be a race condition if readers were not 
waited upon. Then the amount of data written would depend on various 
delays in the system. But that's a horrible application design, not a 
horrible framework.


Andrei


More information about the dmd-concurrency mailing list