]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/pool/test/test_threading.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / pool / test / test_threading.cpp
CommitLineData
7c673cae
FG
1/* Copyright (C) 2011 John Maddock
2*
3* Use, modification and distribution is subject to the
4* Boost Software License, Version 1.0. (See accompanying
5* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8#include <boost/pool/pool_alloc.hpp>
9#include <boost/thread.hpp>
10#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
11#pragma warning(push)
12#pragma warning(disable:4244)
13#endif
14#include <boost/random/mersenne_twister.hpp>
15#include <boost/random/uniform_int_distribution.hpp>
16#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
17#pragma warning(pop)
18#endif
19
20void run_tests()
21{
22 boost::random::mt19937 gen;
23 boost::random::uniform_int_distribution<> dist(-10, 10);
24 std::list<int, boost::fast_pool_allocator<int> > l;
25
26 for(int i = 0; i < 100; ++i)
27 l.push_back(i);
28
29 for(int i = 0; i < 100000; ++i)
30 {
31 int val = dist(gen);
32 if(val < 0)
33 {
34 while(val && l.size())
35 {
36 l.pop_back();
37 ++i;
38 }
39 }
40 else
41 {
42 while(val)
43 {
44 l.push_back(val);
45 --val;
46 }
47 }
48 }
49}
50
51int main()
52{
53 std::list<boost::shared_ptr<boost::thread> > threads;
54 for(int i = 0; i < 10; ++i)
55 {
56 try{
57 threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(&run_tests)));
58 }
59 catch(const std::exception& e)
60 {
61 std::cerr << "<note>Thread creation failed with message: " << e.what() << "</note>" << std::endl;
62 }
63 }
64 std::list<boost::shared_ptr<boost::thread> >::const_iterator a(threads.begin()), b(threads.end());
65 while(a != b)
66 {
67 (*a)->join();
68 ++a;
69 }
70 return 0;
71}
72