Author Topic: managed C++ crash  (Read 91683 times)

nbsystems

  • Newbie
  • *
  • Posts: 5
    • View Profile
managed C++ crash
« 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

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: managed C++ crash
« Reply #1 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.

nbsystems

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: managed C++ crash
« Reply #2 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?

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: managed C++ crash
« Reply #3 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.

nbsystems

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: managed C++ crash
« Reply #4 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.

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: managed C++ crash
« Reply #5 on: May 08, 2012, 12:59:21 PM »
Possibly. I'll look into the implementation changes that would be required.

nbsystems

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: managed C++ crash
« Reply #6 on: May 10, 2012, 11:34:52 PM »
Thanks for looking into it!

nbsystems

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: managed C++ crash
« Reply #7 on: November 10, 2012, 01:03:32 AM »
Have you had a chance to look into this further?