[Boost-bugs] [Boost C++ Libraries] #5754: Bug/design issue with boost::thread::id

Subject: [Boost-bugs] [Boost C++ Libraries] #5754: Bug/design issue with boost::thread::id
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-08-05 01:20:19


#5754: Bug/design issue with boost::thread::id
--------------------------------------+-------------------------------------
 Reporter: ZenJu <zhnmju123@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
  Version: Boost 1.47.0 | Severity: Showstopper
 Keywords: |
--------------------------------------+-------------------------------------
 Hi,

 I have just run into a nasty memory leak which was caused by a circular
 reference due to boost::thread::id.

 The situation is as follows:

 1. Main thread controls several worker thread.
 2. Only one worker thread shall be allowed to report its current status,
 so we need some identifier.
 3. The information which thread shall report, is placed as a
 boost::thread::id into a structure which is shared by main thread and all
 worker threads (via std::shared_ptr)

 4. We happily and unwittingly(!) introduced a circular reference!

 Analysis:
 Main thread successfully joins all worker threads, still there is a
 circular reference.
 Simple reason: boost::thread::id has partial ownership of the
 corresponding thread local storage! Technically it's implemented as an
 intrusive_ptr on boost::detail::thread_data which owns the TLS, in my case
 it's the data of a full blown function object, which I had passed to
 boost::thread.

 In the example above, one of the worker threads shares ownership to the
 shared structure containing a thread::id which shares ownership
 of...surprise ...himself!

 This is IMHO a design bug! A thread::id should not have any ownership of
 its corresponding thread's data, but should be a plain vanilla value type
 without any side-effects.

 Fix is simple, just remove the thread::id's ownership semantics. I really
 hope this gets addresses (soon), since it's fundamental, and IMHO in
 contrast to reasonable expectations.

 Tested with boost v1.47 on MingW/GCC and VC 2010 64-bit

 Best regards, ZenJu

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5754>
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:07 UTC