[dmd-concurrency] Shutdown protocol

Steve Schveighoffer schveiguy at yahoo.com
Thu Jan 21 10:28:36 PST 2010


----- Original Message ----

> From: Andrei Alexandrescu <andrei at erdani.com>
> 
> I worked for three Internet companies during 1997 and then 1999-2001. As fate 
> has it, I never got to directly write low-level networking code. But I worked on 
> and managed projects involving threads and network connections, and worked 
> closely with experts in socket-based networking. I can say I know (or knew at a 
> point) RealDownload as well as I had written it myself. Incidentally I have 
> intimate knowledge regarding shutting sockets down because I was involved in the 
> threading part of such programs so figuring out orderly shutdown was a 
> challenge. I'm not counterspeculating here.

This is not 1999 or 2001.  I'm sure MFC was heavily used in those projects also :)

> One thing is for sure: everybody I know in networking and their sister close the 
> library and let sockets fail when shutting the application down.

I only know what I've developed in my projects, and the most effective and robust shutdown I found involved properly cleaning up sockets.  Having a shutdown time of a few seconds is not terrible, and allows proper cleanup.  I've never had any problems in my applications of having blocking sockets hold up shutdown, because I always write my threads to periodically check for shutdown.

> I think it's tenuous to conceive an application that doesn't terminate when the 
> user wants to terminate it. Even MS Money, which synchronizes online when you 
> shut down (a weird design if you ask me) has a "Exit now" button that does what 
> needs to be done.

It happens all the time.  Even on my Linux laptop I occasionally have to kill a process from the command line because it doesn't exit.  What you want is to hard-wire the "close application" button of the window manager to killing all sockets.  That's no good.  An application should be free to do whatever it wishes when the user wants it to close (save files, flush network data, etc).

> If you exit main, there is no waiting for sockets.

I have no problem with main calling exit() to finish the application after D's main exits.  Kill everything at that point.  But a builtin shutdown facility is not equated to exiting main in my opinion.

-Steve



      


More information about the dmd-concurrency mailing list