[dmd-concurrency] shutting down
Andrei Alexandrescu
andrei at erdani.com
Wed Jan 20 15:37:52 PST 2010
Sean Kelly wrote:
> On Jan 20, 2010, at 1:00 PM, Andrei Alexandrescu wrote:
>
>> Michel Fortin wrote:
>>> Le 2010-01-20 à 15:24, Andrei Alexandrescu a écrit :
>>>> I think threads shouldn't be able to do much during shutdown. For
>>>> example I don't think they should suddenly open sockets. How about
>>>> opening files? Or calling system()? Any ideas on a unified approach?
>>> Why do you think that?
>>
>> I'm thinking, there are too many programs that hang when I want to end
>> them just because some thread inside is waiting for a socket. I think
>> that any operation that could block for an arbitrary amount of time
>> should be disallowed during shutdown.
>
> What if the program is logging to a remote host and wants to log a
> shutdown event?
I think it should do so in main. Nevertheless, my intuition is that we
can use a judgment call a la "file operations are considered fast so we
won't kill them" even though technically a file could be opened over a
network connection.
>> What sockets library do today is, they offer a global close_library
>> function. Once that is called, all pending socket connections and all
>> new socket connections fail immediately.
>
> If it helps, here is the current process shutdown behavior:
>
> 1. join all non-daemon threads (non-daemon is the default)
> 2. set Runtime.isHalting to true
> 3. call module dtors
> 4. cleanup and exit
>
> What's missing here is that daemon threads are forcibly terminated when
> the process exits, while following the shotdown approach there should be
> a step 3a that causes messaging to throw, etc. Instead of setting an
> isDaemon flag in user code, some other means could be used. Perhaps
> calling detach() on a Tid makes the thread a daemon thread?
If there's no overwhelming evidence of daemons' usefulness, I'd just
undefine them. Remember that Twilight Zone famous solution to getting
rid of a d(a)emon? "Get lost." Pretty awesome.
http://en.wikipedia.org/wiki/I_of_Newton
Andrei
More information about the dmd-concurrency
mailing list