[dmd-concurrency] Shutdown protocol

Michel Fortin michel.fortin at michelf.com
Wed Jan 20 16:42:44 PST 2010


Le 2010-01-20 à 18:54, Andrei Alexandrescu a écrit :

> 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.

You can easily transform the file copy program to add the race condition though. The file copy example has one reading and one writing thread. Now let's add a processing thread in the middle that does something to the data (could be compression or encryption):

	reading -> processing -> writing

Once the reading thread has finished, some parts will be in the process of being processed, other parts will be in the process of being written. Now, assume writing is faster than processing: the writing thread will finish what it has and wait for new messages (those parts the processing thread is still processing), but at that moment it will be interrupted by a shutdown. After that, while the processing thread slowly advance with its processing it sends messages to a dead writing thread.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list