just::thread Support Forum

General Category => General Discussion about just::thread => Topic started by: nbsystems on January 23, 2012, 08:44:27 PM

Title: managed C++ crash
Post by: nbsystems on January 23, 2012, 08:44:27 PM
I'm using your current release with Visual Studio 2008.
I find that managed C++ applications or mixed mode applications that link to your debug dll crash when the module is loaded. Merely including <thread> is enough to cause this crash.
It does not crash in release mode.

Is your library tested in managed contexts?
thanks
Title: Re: managed C++ crash
Post by: Anthony Williams on January 23, 2012, 09:27:00 PM
Just::Thread does not work with managed or mixed-mode code since it uses thread-exit callbacks which are not supported for executables and DLLs containing managed code.
Title: Re: managed C++ crash
Post by: nbsystems on January 23, 2012, 11:16:39 PM
Thanks for the reply.

What exactly is the restriction?
The current setup of this application is a managed application which loads and uses a native COM dll. Just::Thread is used by the native COM dll and that works fine.
We would like to add some managed code to this dll, but the code using your library would still be entirely native. What is it exactly that happens during the module load process that causes this crash?
Title: Re: managed C++ crash
Post by: Anthony Williams on January 24, 2012, 08:42:24 AM
The restriction is that a mixed-mode or managed DLL cannot contain TLS callbacks.

Just::Thread uses TLS callbacks to ensure that the process-wide and thread-specific data it uses is correctly constructed and destroyed, so it cannot be used in a mixed-mode DLL.

Note that this is about the DLL itself, not the process: Just::Thread can be used in a native DLL called from managed code without problems, as you have discovered.
Title: Re: managed C++ crash
Post by: nbsystems on May 08, 2012, 01:09:52 AM
We've been researching this issue further, hoping to find a workaround. We've found that the Boost thread library uses TLS callbacks for similar purposes. However, in Boost::thread it's possible to disable the TLS-callback-based automatic cleanup and free thread-specific resources manually instead (although documentation of this option is scant). This would presumably allow the library to be used in a mixed-mode DLL.

Is there a chance that such an option could be implemented within Just::Thread? We would prefer not to switch to the Boost thread library if possible.
Title: Re: managed C++ crash
Post by: Anthony Williams on May 08, 2012, 12:59:21 PM
Possibly. I'll look into the implementation changes that would be required.
Title: Re: managed C++ crash
Post by: nbsystems on May 10, 2012, 11:34:52 PM
Thanks for looking into it!
Title: Re: managed C++ crash
Post by: nbsystems on November 10, 2012, 01:03:32 AM
Have you had a chance to look into this further?