[dmd-concurrency] shutting down

Andrei Alexandrescu andrei at erdani.com
Thu Jan 21 09:08:22 PST 2010


Steve Schveighoffer wrote:
> You're getting closer to a function that effectively and artificially
> kills all threads.  I don't really like this scenario, a thread
> should be able to do whatever it wants, even during shutdown.  For
> instance, let's say you log that a thread is ending via a finally
> clause at the end of the thread.  This works no problem with default
> logging configuration since the log is to disk, but one enterprising
> user has all his applications log to a network socket, so he
> configures the logging library of your app to use a network socket to
> store data.  All of a sudden, the logs go away because doing the log
> causes an exception.  I think this is unacceptable and hard to plan
> for.  You can't possibly know all the uses of sockets in underlying
> functions that a thread may call on shutdown.  I think all those
> should be allowed to proceed.

I understand your concern, but I also like the following scenario when 
I'm at the airport:

1. I start Firefox

2. There is no wireless available

3. All my many pages are spinning waiting to load

4. I close Firefox

It's instant. I want to prevent threads started by arbitrary libraries 
for various purposes from being able to delay application shutdown 
indefinitely.

> Not to mention you are relying on the network library providing such
> a function which might not exist (killing all socket communication is
> not a standard socket function).  Someone who wants this behavior can
> implement it manually in environments where it is provided -- I don't
> think it should be a standard practice.

That function always exists (see my previous post).

> Normal practice is to not block on a socket indefinitely (i.e. wait
> for data in a loop with a timeout, checking for shutdown every loop),
> or wait for both socket data *and* another event.  In some OSes, the
> latter is not possible, and I think Phobos should try to use the
> least common denominator.

Normal practice is to close the socket library, and it will instantly 
fail all pending and new calls. That makes both threads and the main 
program much easier to write.


Andrei


More information about the dmd-concurrency mailing list