1.36 Threads/ASIO causing SEGV when cleaning up thread specific storage

I am trying to run my unit previous unit tests with the new 1.36 release, but SEGV is being thrown upon exit. No faults are thrown using 1.34.1, and no code is changed between versions. But for some reason, it keeps throwing! The TSS callback functions are empty as below, as no TSS variables own their data. static void TssCleanup(AType* tss) { } Call stack: msvcr80d.dll!_free_base(void * pBlock=0x00fa8bd8) Line 109 + 0x13 bytes C ntdll.dll!7c901046() test.exe!boost::detail::lightweight_mutex::scoped_lock::scoped_lock(boost::detail::lightweight_mutex & m={...}) Line 94 + 0xe bytes C++ test.exe!boost::detail::allocator_impl<20,4>::dealloc(void * pv=0x002d19e0) Line 149 C++ test.exe!boost::detail::sp_counted_impl_pd<boost::thread_specific_ptr<AClass>::run_custom_cleanup_function *,boost::detail::do_heap_delete<boost::thread_specific_ptr<AClass>::run_custom_cleanup_function> >::operator delete(void * p=0x002d19e0) Line 175 + 0x9 bytes C++ test.exe!boost::detail::sp_counted_impl_pd<boost::thread_specific_ptr<AClass>::run_custom_cleanup_function *,boost::detail::do_heap_delete<boost::thread_specific_ptr<AClass>::run_custom_cleanup_function> >::`scalar deleting destructor'() + 0x27 bytes C++ test.exe!boost::detail::sp_counted_base::destroy() Line 66 + 0x22 bytes C++ test.exe!boost::detail::sp_counted_base::weak_release() Line 116 + 0xf bytes C++ test.exe!boost::detail::sp_counted_base::release() Line 105 C++ test.exe!boost::detail::shared_count::~shared_count() Line 220 C++ test.exe!boost::shared_ptr<boost::detail::tss_cleanup_function>::~shared_ptr<boost::detail::tss_cleanup_function>() + 0x19 bytes C++ test.exe!boost::detail::tss_data_node::~tss_data_node() + 0x12 bytes C++ test.exe!boost::detail::tss_data_node::`scalar deleting destructor'() + 0xf bytes C++ test.exe!boost::detail::heap_delete<boost::detail::tss_data_node>(boost::detail::tss_data_node * data=0x00057498) Line 380 C++ test.exe!boost::`anonymous namespace'::run_thread_exit_callbacks() Line 140 + 0x9 bytes C++ test.exe!on_thread_exit() Line 580 C++ msvcr80d.dll!doexit(int code=0, int quick=0, int retcaller=0) Line 553 C msvcr80d.dll!exit(int code=0) Line 398 + 0xd bytes C test.exe!__tmainCRTStartup() Line 610 C test.exe!mainCRTStartup() Line 414 C I have searched for this problem long and hard, if I have missed something please let me know. I currently cannot reproduce the error with simplified code. Cheers, spider. -- View this message in context: http://www.nabble.com/1.36-Threads-ASIO-causing-SEGV-when-cleaning-up-thread-specific-storage-tp19428245p19428245.html Sent from the Boost - Users mailing list archive at Nabble.com.

spiderlama <spiderlama@gmail.com> writes:
I am trying to run my unit previous unit tests with the new 1.36 release, but SEGV is being thrown upon exit. No faults are thrown using 1.34.1, and no code is changed between versions. But for some reason, it keeps throwing!
The TSS callback functions are empty as below, as no TSS variables own their data.
For an access violation with that callstack, the heap must be corrupt (the error is happening when a shared_ptr destroys the count object). Without the code I cannot help further. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Anthony Williams-4 wrote:
For an access violation with that callstack, the heap must be corrupt (the error is happening when a shared_ptr destroys the count object). Without the code I cannot help further.
Unfortunately I have not been able to reproduce this problem in any code that is postable. It does seem strange that run_thread_exit_callbacks() calls a TSS' custom cleanup function with a null argument, even if cleanup has already occurred. Is this used when a thread exits before the thread_specific_ptr is destructed? -- View this message in context: http://www.nabble.com/1.36-Threads-ASIO-causing-SEGV-when-cleaning-up-thread... Sent from the Boost - Users mailing list archive at Nabble.com.

Anthony Williams-4 wrote:
spiderlama <spiderlama@gmail.com> writes:
I am trying to run my unit previous unit tests with the new 1.36 release, but SEGV is being thrown upon exit. No faults are thrown using 1.34.1, and no code is changed between versions. But for some reason, it keeps throwing!
The TSS callback functions are empty as below, as no TSS variables own their data.
For an access violation with that callstack, the heap must be corrupt (the error is happening when a shared_ptr destroys the count object). Without the code I cannot help further.
Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Here's some code that breaks: boost::thread_specific_ptr<int> tss; tss.reset(new int(10)); It seems that the shared_ptr (inside thread_specific_ptr) uses an internal memory manager for the reference counter which has already been destructed so when the shared_ptr tries to delete this memory it goes boom! -- View this message in context: http://www.nabble.com/1.36-Threads-ASIO-causing-SEGV-when-cleaning-up-thread... Sent from the Boost - Users mailing list archive at Nabble.com.

spiderlama <spiderlama@gmail.com> writes:
Here's some code that breaks:
boost::thread_specific_ptr<int> tss; tss.reset(new int(10));
It seems that the shared_ptr (inside thread_specific_ptr) uses an internal memory manager for the reference counter which has already been destructed so when the shared_ptr tries to delete this memory it goes boom!
On its own, that doesn't break when I try it. What are your build settings? Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Ok found the solution. It seems that the (initial threads) thread_exit_callback is being called AFTER the TSS's built in heap has been cleaned. Talk about dangling pointers! This can be fixed by declaring a static tss variable in your class :-D cheers, spider. -- View this message in context: http://www.nabble.com/1.36-Threads-ASIO-causing-SEGV-when-cleaning-up-thread... Sent from the Boost - Users mailing list archive at Nabble.com.

spiderlama <spiderlama@gmail.com> writes:
Ok found the solution. It seems that the (initial threads) thread_exit_callback is being called AFTER the TSS's built in heap has been cleaned. Talk about dangling pointers!
If that's the case, this is a serious issue, and I'd like to fix it. What build settings are you using? Are you using the DLL or the LIB version of boost thread? Are you using a static C runtime or a DLL runtime? Thanks, Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Anthony Williams-4 wrote:
If that's the case, this is a serious issue, and I'd like to fix it. What build settings are you using? Are you using the DLL or the LIB version of boost thread? Are you using a static C runtime or a DLL runtime?
I am building an EXE including MFC libraries, statically linking to the Boost 1.36 thread library, and using the Multi-threaded Debug DLL (/MDd) runtime. Let me know if I can provide any more information! Cheers, spider -- View this message in context: http://www.nabble.com/1.36-Threads-ASIO-causing-SEGV-when-cleaning-up-thread... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Anthony Williams
-
spiderlama