--- Comment #5 from Andrej Mitrovic <> 2011-06-04 
12:33:33 PDT ---
This might not be directly relevant to this bug report, but I thought I'd share
the story anyway. I currently have this in one of my projects:

An extern(C) callback is passed to a device driver. The user-code then calls
driver.start(), and the driver starts a new high-priority/ISR routine which
calls the callback at some predetermined rate.

Now, in my main() function I have this (pseudocode):

scope(exit) driver.stop();  // Calling this before app exit on started drivers
is crucial
while (engineRunning) { }   // shared bool of the engine state

That works well for the user thread, if an exception is thrown in the user
thread scope exit will be ran and the driver is released. 

But if in the callback thread an exception is thrown and is uncaught it will
shut down my application but it won't call driver.stop(), because it's in a
different thread which main doesn't directly know about.

I've had this happen to me several times with ASIO Audio drivers. Most of the
times, the app will quit but appear frozen in taskbar and the device driver
won't get released even if I do a cold-reboot of my soundcard (it's external
with its own power source). It then takes a few minutes or a pc-reboot for the
driver to actually get released.

But worse things have happened, I've had several BSODs as well. It wasn't
obvious to me what was going on until I've realized that driver.stop() never
gets called. 

So now my current workaround is to wrap any code in the callback with a

extern(C) callback(args..)
    catch (Throwable)
        engineRunning = false;

If an exception is thrown the app can call driver.stop() (since the user thread
keeps checking the state ofr the shared engineRunning boolean), and then the
app can quit safely.

Quitting forcefully on any errors might not be the best thing to do. But maybe
my use-case is a special one, and this doesn't happen that frequently outside
of using device drivers or other types of external resources.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to