#include #include #include #include class Func { public: typedef boost::mutex mutex_type; typedef boost::lock_guard lock_type; typedef void result_type; private: static int counter_; static mutex_type m_; public: Func() { lock_type lock(m_); ++counter_; } Func(const Func& f) { lock_type lock(m_); ++counter_; } ~Func() { lock_type lock(m_); --counter_; } static int get() { lock_type lock(m_); return counter_; } result_type operator()(int n) { if (n < 1) { return; } typedef boost::task::handle< void > handle_type; handle_type h1( boost::task::async( boost::task::make_task( Func(), n - 1) ) ); handle_type h2( boost::task::async( boost::task::make_task( Func(), n - 1 ) ) ); std::vector v; v.push_back(h1); v.push_back(h2); boost::task::waitfor_all(v.begin(), v.end()); } }; int Func::counter_ = 0; Func::mutex_type Func::m_; int main() { using std::cout; using std::endl; typedef boost::task::static_pool< boost::task::unbounded_twolock_fifo > pool_type; pool_type pool(pool_type::bind_to_processors()); const int recursion_levels = 15; while(1) { boost::task::handle< void > h( boost::task::async( boost::task::make_task( Func(), recursion_levels ), pool ) ); h.wait(); cout << "Undeleted functors: " << Func::get() << endl; } }