Boost logo

Boost Users :

From: svanechel (svanechel_at_[hidden])
Date: 2002-04-25 08:55:26


Hi there,

I've encountered a curious problem when using thread_specific_ptr. We
are developing a Win32 Service and for each thread we need an object
that stays alive for as long as the thread runs (except for the main
thread).

So we created a dll and in its DllMain function we did something like
this:

boost::thread_specific_ptr<SomeClass> someClass;

BOOL WINAPI DllMain(
 HINSTANCE hinstDLL,
 DWORD fdwReason,
 LPVOID lpvReserved )
{
  switch ( fdwReason )
  {
  case DLL_THREAD_ATTACH:
     someClass.reset( new SomeClass ); // Breakpoint 1
  case DLL_THREAD_DETACH:
     someClass.reset(); // Breakpoint 2
  }
}

And now comes the curious bit: If you build this dll and implicitly
link it with the exe the exe's startup code hangs in GetModuleFileName
(). This is the call stack upto that point

_setargv (STDARGV.C)
__getmainargs (CRTLIB.C)
WinMainCRTStartup (CRTEXE.C)

At that point the code hasn't reached Breakpoint 1 yet (it's still in
the exe's startup code in the main thread and we are not interested
in the main thread)

It is not the class we are allocating. We tried it with an empty
class and that produced the same result. However, if we stored an
object in a TLS slot allocated with the API, everything works.

It probably has nothing to do with the exe being a service either,
since the same dll with linked to a normal exe had the same problems.

To complicate matters even further we reached Breakpoint 1 in a
number of runs, but as soon as we left DllMain in those instances the
application hanged again. If you break then you see from the call
stack that the code is running somewhere in NTDll.

Are we using thread_specific_ptr in a way that it wasn't meant to be
used, or did we encounter a real problem here? I've used
thread_specific_ptr before and had no problems then.

PS: We develop under Windows 2000 on a Compaq Evo W6000 dual
processor machine, using MSVC 6, SP 5 and the 08/2001 version of the
platform SDK. The service can run both under the Local System Account
or under an account with absolutely no privileges at all.

Sven Van Echelpoel


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net