]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/example/thread_group.cpp
1 // Copyright (C) 2001-2003
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/thread/thread.hpp>
9 #include <boost/detail/lightweight_test.hpp>
14 void increment_count()
16 boost::unique_lock
<boost::mutex
> lock(mutex
);
17 std::cout
<< "count = " << ++count
<< std::endl
;
20 boost::thread_group threads2
;
21 boost::thread
* th2
= 0;
23 void increment_count_2()
25 boost::unique_lock
<boost::mutex
> lock(mutex
);
26 BOOST_TEST(threads2
.is_this_thread_in());
27 std::cout
<< "count = " << ++count
<< std::endl
;
33 boost::thread_group threads
;
34 for (int i
= 0; i
< 3; ++i
)
35 threads
.create_thread(&increment_count
);
38 #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
40 boost::thread_group threads
;
41 for (int i
= 0; i
< 3; ++i
)
42 threads
.create_thread(&increment_count
);
43 threads
.interrupt_all();
48 boost::thread_group threads
;
49 boost::thread
* th
= new boost::thread(&increment_count
);
50 threads
.add_thread(th
);
51 BOOST_TEST(! threads
.is_this_thread_in());
55 boost::thread_group threads
;
56 boost::thread
* th
= new boost::thread(&increment_count
);
57 threads
.add_thread(th
);
58 BOOST_TEST(threads
.is_thread_in(th
));
59 threads
.remove_thread(th
);
60 BOOST_TEST(! threads
.is_thread_in(th
));
66 boost::unique_lock
<boost::mutex
> lock(mutex
);
67 boost::thread
* th2
= new boost::thread(&increment_count_2
);
68 threads2
.add_thread(th2
);
72 return boost::report_errors();