Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#12049 closed Bugs (fixed)

Assertion failure from detached threads during shutdown

Reported by: Braden McDaniel <braden@…> Owned by: viboes
Milestone: Boost 1.61.0 Component: thread
Version: Boost 1.60.0 Severity: Regression
Keywords: Cc:

Description

I'm observing assertion failures coming from detached threads during shutdown (i.e., the main thread is in static destruction):

libs/thread/src/pthread/thread.cpp:149: void boost::detail::set_current_thread_data(boost::detail::thread_data_base*): Assertion `!pthread_setspecific(current_thread_tls_key,new_data)' failed.

I'm seeing this on both Linux and Mac platforms; and the problem appears to have been introduced in the 1.60.0 release; 1.59.0 did not exhibit the problem.

Stacks from these threads at the time of the assertion failure look like this:

#0	0x00007fff95104002 in __pthread_kill ()
#1	0x000000010356944e in pthread_kill ()
#2	0x00007fff9ef566e7 in abort ()
#3	0x00007fff9ef1ddc7 in __assert_rtn ()
#4	0x0000000100a4ff90 in boost::detail::set_current_thread_data(boost::detail::thread_data_base*) at /Users/mcdanb/Build/buildpackages/API/pkg_build/boost_1_60_0/libs/thread/src/pthread/thread.cpp:149
#5	0x0000000100a50141 in boost::(anonymous namespace)::thread_proxy(void*) at /Users/mcdanb/Build/buildpackages/API/pkg_build/boost_1_60_0/libs/thread/src/pthread/thread.cpp:185
#6	0x00000001035679f9 in _pthread_body ()
#7	0x0000000103567976 in _pthread_start ()
#8	0x0000000103564fbd in thread_start ()

So, the thread appears to have completed any work it was doing. The problem is not reproducible 100% of the time; but when it happens (which is not infrequent), I appear to see one assertion for each detached thread that is still present during static destruction.

Change History (5)

comment:1 by viboes, 7 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:2 by viboes, 7 years ago

I suspect the change

https://github.com/boostorg/thread/commit/242cf35c519fc886c13789f1f9a049571fde4cdc

could be the cause. Please, could you try to rollback this one first?

comment:3 by viboes, 7 years ago

Milestone: To Be DeterminedBoost 1.61.0
Last edited 7 years ago by viboes (previous) (diff)

comment:4 by viboes, 7 years ago

Resolution: fixed
Status: assignedclosed

comment:5 by blastrock, 7 years ago

Hi,

I wanted to investigate a bit on this bug, do you have a minimal example? I tried to produce one with the description of the bug and wrote this:

#include <boost/thread.hpp>
#include <thread>
#include <unistd.h>

boost::thread_specific_ptr<int> p;

int main()
{
  std::thread th([]{ p.reset(new int); usleep(200000); });
  //th.join();
  th.detach();
  pthread_exit(0);
}

But this program works fine on my Linux, even if I comment the pthread_exit or if I invert the reset() and the usleep() calls.

Note: See TracTickets for help on using tickets.