Boost logo

Threads-Devel :

Subject: [Threads-devel] unbind passed function to the thread constructor after real thread exits
From: dadrus_at_[hidden]
Date: 2009-02-19 04:45:59

I'm not very familiar with the implementation of Boost.Thread. However i think there is a bug (see my simplified example):

class foo {
  // some members

  void func(int arg1) {
    // some calculation

int main() {
  boost::smart_ptr<foo> f(new foo); // a

  boost::thread t(boost::bind(&foo::func, f, 1)); // b

  t.join(); // c

  f.reset(); // d

  return 1;

step 1: we've only one reference to foo object after a.
step 2: after b we've 2 references to foo
step 3: after c we've still have 2 references even though the real thread of execution exit
step 4: after d we've 1 reference which is store in t object.

I think that a cler solution would be to unbind a function object passed to the thread constructor after real thread of execution exit. Otherwise
one can generate a lot of memory leaks.

Is this a known problem?
Are there plans to fix it?

By the way Boost.Threadpool (boost vault) has the same problem.

Dimitrij Drus

Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
für nur 17,95 Euro/mtl.!*

Threads-Devel list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at