[task] functor passed to a boost::task::task not always destroyed?

I wrote a short test program to check that each copy construction of a functor passed to a boost::task::task and boost::task::async was balanced by a corresponding destructor call. This is indeed the case when the task is run in a thread pool but it seems as if one destructor call is missing when the task is submitted to to boost::task::async with a boost::task::new_thread execution policy. Here is the a short test program and the resulting output. For comparison, the same functor is also passed directly to a boost::thread, which behaves as expected. The program was compiled using Visual C++ 2005 (SP1), and boost 1.39.0 with the latest Boost.Task library from the vault dropped in. Any ideas? Am I missing something? Best regards Harald --- Output: Running Runnable as a task Runnable() [0012FF57] Runnable(const Runnable&) [0012FE88] Runnable(const Runnable&) [0012FE40] Runnable(const Runnable&) [00463B9C] ~Runnable() [0012FE40] ~Runnable() [0012FE88] Runnable::operator() [00463B9C] ~Runnable() [0012FF57] Running Runnable directly on a thread Runnable() [0012FF33] Runnable(const Runnable&) [0012FE8C] Runnable(const Runnable&) [0012FE5C] Runnable(const Runnable&) [0012FDDC] Runnable(const Runnable&) [001541D8] ~Runnable() [0012FDDC] ~Runnable() [0012FE5C] ~Runnable() [0012FE8C] Runnable::operator() [001541D8] ~Runnable() [001541D8] ~Runnable() [0012FF33] --- Test program: #include <boost/thread.hpp> #include <boost/task.hpp> #include <iostream> void print(const std::string& s, void* instance = 0) { static boost::mutex mutex; boost::lock_guard<boost::mutex> guard(mutex); std::cout << s; if (instance) std::cout << " [" << instance << "]"; std::cout << std::endl; } struct Runnable { Runnable() { print("Runnable()", this); } Runnable(const Runnable&) { print("Runnable(const Runnable&)", this); } ~Runnable() { print("~Runnable()", this); } void operator()() { print("Runnable::operator()", this); } }; int main() { { print("Running Runnable as a task"); Runnable r; boost::task::handle<void> h = boost::task::async(boost::task::make_task(r), boost::task::new_thread()); h.wait(); } { print("Running Runnable directly on a thread"); Runnable r; boost::thread thread(r); thread.join(); } return 0; }

I've added a new version to boost vault - it should fix the problem. Oliver Am Dienstag 25 August 2009 11:48:11 schrieb Harald Winroth:
I wrote a short test program to check that each copy construction of a functor passed to a boost::task::task and boost::task::async was balanced by a corresponding destructor call. This is indeed the case when the task is run in a thread pool but it seems as if one destructor call is missing when the task is submitted to to boost::task::async with a boost::task::new_thread execution policy.
Here is the a short test program and the resulting output. For comparison, the same functor is also passed directly to a boost::thread, which behaves as expected. The program was compiled using Visual C++ 2005 (SP1), and boost 1.39.0 with the latest Boost.Task library from the vault dropped in.
Any ideas? Am I missing something?
Best regards Harald
participants (2)
-
Harald Winroth
-
k-oli@gmx.de