[Boost-bugs] [Boost C++ Libraries] #4345: thread::id and joining problem with cascade of threads

Subject: [Boost-bugs] [Boost C++ Libraries] #4345: thread::id and joining problem with cascade of threads
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-06-15 14:57:28


#4345: thread::id and joining problem with cascade of threads
----------------------------------------------------------+-----------------
 Reporter: bartek szurgot <bartosz.szurgot@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: thread
  Version: Boost 1.43.0 | Severity: Problem
 Keywords: |
----------------------------------------------------------+-----------------
 i believe there is a problem when saving thread's ids in an external (for
 a thread) collection, when joining cascade of threads and collection lives
 on.

 example code, showing this issue has been attached this this report. what
 happens there:
   1. main() creates collection of thread::id objects (i.e. Data)
   2. main() creates two threads (in classes A and B)
   3. ThreadJoiner helper class interrupts and joins threads in d-tor, and
 so main() int+join thread in B class' instance, that in turn int+join A
 class' instance thread (member of B object)
   4. check if threads exited, as they should.

 each thread increments global counter when entering operator()() and
 decrements it when leaving operator()()'s scope, so when leaving scope of
 ThreadJoiner root object all threads should be already joined.
 it happens this way (as expected) as long as one does not save
 thread::ids. if they are saved, and live longer then thread, threads are
 not (always) joined properly (in attached example program: assertion on
 global counter equals 0 fails). it looks like race, but is reproducible in
 ~95% of the cases.

 problem does not seem to appear when threads are run directly, and joined
 from main as well (not cascade).

 in example code there are 2 ways to make code work as expected:
   1. uncomment main.cpp:139 (deallocation of collection of saved IDs
 before calling joins in d-tors)
   2. change main.cpp:32 from '#if 1' to '#if 0' - this changes collection
 to hold std::string (generated via stream, from boost::thread::id) from
 boost::thread::id

 i was able to reproduce this issue with the same results with boost
 versions:
   1. 1.38
   2. 1.40
   3. 1.43
   4. today's trunk
 toolchain is g++ 4.4.x under Linux (Debian and Ubuntu).

 to build and run example code extract bzip2 archive, enter directory and
 run:
 make && gen/debug/a.out

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4345>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:03 UTC