1 // Copyright (C) 2011 Vicente J. Botet Escriba
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #define BOOST_THREAD_USES_MOVE
8 #include <boost/config.hpp>
9 #include <boost/thread/thread.hpp>
10 #include <boost/thread/mutex.hpp>
11 #include <boost/thread/csbl/list.hpp>
12 //#include <boost/interprocess/smart_ptr/shared_ptr.hpp>
13 #include <boost/smart_ptr.hpp>
15 #include <boost/detail/lightweight_test.hpp>
24 template <typename TC>
25 void join_all(TC & tc)
27 for (typename TC::iterator it = tc.begin(); it != tc.end(); ++it)
34 void increment_count()
36 boost::unique_lock<boost::mutex> lock(mutex);
37 std::cout << "count = " << ++count << std::endl;
45 BOOST_CONSTEXPR default_delete() BOOST_NOEXCEPT {} //= default;
47 default_delete(const default_delete<U>&) BOOST_NOEXCEPT
49 void operator()(T* ptr) const
59 typedef boost::shared_ptr<boost::thread > thread_ptr;
60 //typedef boost::interprocess::shared_ptr<boost::thread, std::allocator<boost::thread>, default_delete<boost::thread> > thread_ptr;
61 typedef boost::csbl::list<thread_ptr > thread_ptr_list;
62 thread_ptr_list threads;
63 for (int i = 0; i < 10; ++i)
65 //threads.push_back(BOOST_THREAD_MAKE_RV_REF(thread_ptr(new boost::thread(&increment_count))));
66 threads.push_back(thread_ptr(new boost::thread(&increment_count)));
68 BOOST_TEST(threads.size()==10);
70 for (thread_ptr_list::iterator it = threads.begin(); it != threads.end(); ++it)
77 typedef boost::shared_ptr<boost::thread > thread_ptr;
78 //typedef boost::interprocess::shared_ptr<boost::thread, std::allocator<boost::thread>, default_delete<boost::thread> > thread_ptr;
79 typedef boost::csbl::list<thread_ptr > thread_ptr_list;
80 thread_ptr_list threads;
81 for (int i = 0; i < 10; ++i)
83 //threads.push_back(BOOST_THREAD_MAKE_RV_REF(thread_ptr(new boost::thread(&increment_count))));
84 threads.push_back(thread_ptr(new boost::thread(&increment_count)));
86 BOOST_TEST(threads.size()==10);
87 thread_ptr sth(new boost::thread(&increment_count));
88 threads.push_back(sth);
89 BOOST_TEST(threads.size()==11);
91 BOOST_TEST(threads.size()==10);
94 for (thread_ptr_list::iterator it = threads.begin(); it != threads.end(); ++it)
100 return boost::report_errors();