Boost logo

Boost :

From: Pitz, James R (James.Pitz_at_[hidden])
Date: 2001-10-12 12:26:28


At least in Win32 (inferred from use of DLL_PROCESS_DETATCH), all threads
except the processes main thread will have terminated by the time the static
destructors execute. You can never block in DLL_PROCESS_DETACH waiting on
another thread, this will always deadlock. There are a few strategies that
you can use, some Win32 specific, others more portable, depending on your

You can contact me off the boost group since this is probably not boost

Randy Pitz

-----Original Message-----
From: Jonathan H Lundquist [mailto:jhl_at_[hidden]]
Sent: Friday, October 12, 2001 11:16 AM
To: 'boost_at_[hidden]'
Subject: [boost] threads vs. dllmain

I'm having a problem that I wouldn't normally look to this group to assist
with (as it's in non-boost code), however I can't find an answer on
comp.programming.threads; so, I took a look at boost threads in hopes it had
been solved there, and as far as I can tell it would suffer from the same

I have a worker thread running in a dll, for which I have no control over
the process lifetime. When the process exits the dll is going to run its
static destructors. The thread accesses static data (properly
synchronized), so I need to arrange for it to terminate before static
destructors are run. If I give it some kind of signal to terminate, and
then attempt to wait for it to do so in dllmain DLL_PROCESS_DETACH, then I
deadlock due to the serialization of dllmain.

It looks to me like boost threads would have exactly the same problem if the
main thread attempted to join worker threads at DLL_PROCESS_DETACH time.
Any ideas on how one can correctly ensure all but the main thread have
terminated before static destructors are run in a dll would be appreciated.
Thank you.

Info: Unsubscribe:

Your use of Yahoo! Groups is subject to

Boost list run by bdawes at, gregod at, cpdaniel at, john at