// Copyright (C) 2001-2003 // William E. Kempf // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include int g_count = 0; boost::mutex g_mutex; void increment_count() { boost::unique_lock lock(g_mutex); std::cout << "count = " << ++g_count << std::endl; } boost::thread_group g_threads2; void increment_count_2() { boost::unique_lock lock(g_mutex); BOOST_TEST(g_threads2.is_this_thread_in()); std::cout << "count = " << ++g_count << std::endl; } int main() { { boost::thread_group threads; for (int i = 0; i < 3; ++i) threads.create_thread(&increment_count); threads.join_all(); } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS { boost::thread_group threads; for (int i = 0; i < 3; ++i) threads.create_thread(&increment_count); threads.interrupt_all(); threads.join_all(); } #endif { boost::thread_group threads; boost::thread* th = new boost::thread(&increment_count); threads.add_thread(th); BOOST_TEST(! threads.is_this_thread_in()); threads.join_all(); } { boost::thread_group threads; boost::thread* th = new boost::thread(&increment_count); threads.add_thread(th); BOOST_TEST(threads.is_thread_in(th)); threads.remove_thread(th); BOOST_TEST(! threads.is_thread_in(th)); th->join(); delete th; } { { boost::unique_lock lock(g_mutex); boost::thread* th2 = new boost::thread(&increment_count_2); g_threads2.add_thread(th2); } g_threads2.join_all(); } return boost::report_errors(); }