[dmd-concurrency] Shutdown protocol

Andrei Alexandrescu andrei at erdani.com
Thu Jan 21 10:10:55 PST 2010


Steve Schveighoffer wrote:
> ----- Original Message ----
> 
>> From: Andrei Alexandrescu <andrei at erdani.com>
>> Steve Schveighoffer wrote:
>>> ----- Original Message ----
>>>
>>>> From: Andrei Alexandrescu 
>>>>
>>>> "The function terminates any pending operations on the handle and discards 
>> any outstanding data. If a thread is blocking a call to Wininet.dll, another 
>> thread in the application can call InternetCloseHandle on the Internet handle 
>> being used by the first thread to cancel the operation and unblock the first 
>> thread."
>>>> This is why you can close a browser instantly even though there may be a 
>> dozen pages still waiting to load.
>>> I disagree.  A browser "closing instantly" just means its UI is hidden.  Watch 
>> the process in Task Manager, it lingers for quite a few seconds.
>>
>> The actual process shutdowns next to instantly on all my computers. I can say 
>> I'm positive it does not use the method you are suggesting in your other message 
>> (readWithShutdown).
>>
> 
> I can't say what method it uses to shut down.  I don't see how you can either unless you read the code.

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.

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.

> What I can say is I've seen Firefox linger and even hang when I shut it down.  Often times I accidentally shut down firefox, and go to reopen it in about 5 seconds, and it says it can't start because there's already a process running and that process is shutting down.  Clearly it does some sort of cleanup, whether part of that is to wait for socket reads to time out, I'm not sure.
> 
> My larger point, however, is that the socket-shutdown facility you want to have is available to D applications.  But making it a *required* part is too much.  Maybe applications that don't shut down using this method don't make it on to your laptop, but that's hardly a reason to require all D applications to do it.  You are not the only user of D applications, and web browsing is not the only use-case for threading and sockets.

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.

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


Andrei


More information about the dmd-concurrency mailing list