winmm: Allow a FORCE_SHUTDOWN on driver close?

Peter Beutner p.beutner at gmx.net
Sat Apr 21 09:46:29 CDT 2007


Maarten Lankhorst schrieb:
> After trying to implement the alsa mixer I came across a problem: If
> winmm is unloading, a deadlock could occur if during unloading it's
> waiting for another thread.
> 
> In winmm itself this isn't much of a problem: there aren't any threads.
> 
> However, the drivers used by winmm may have threads, and if the
> application doesn't shut down their drivers properly, it could be
> possible that a deadlock occurs when the drivers unload because winmm
> unloads.
> 
> For that reason I propose to add a flag that's passed to the sound
> drivers that signals a shutdown in DLL_DETACH context, so that drivers
> can choose to call TerminateThread instead of waiting tidily for the
> thread to finish running.
> 
> It's not pretty, but I don't see another way how to make sure that
> deadlocks won't occur when unloading winmm. I'm open for other
> suggestions though.

AFAIK you get the DRVM_EXIT message only when winmm is unloading.
Alternatively you could do it in response to the DRV_CLOSE message which winmm
sends just before it tries to unload the driver.

That said I don't see how your code in ALSA_MixerExit() could deadlock.
It effectively tries to exit the thread the same way as MIX_Close, doesn't it?
So the thread should exit safely.
Imo the question is rather why the thread isn't exiting and you are waiting
forever. Forcibly calling TerminateThread just covers the problem.



More information about the wine-devel mailing list