]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/pool/test/test_threading.cpp
update sources to v12.2.3
[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
b32b8144 8#include <iostream>
7c673cae
FG
9#include <boost/pool/pool_alloc.hpp>
10#include <boost/thread.hpp>
11#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
12#pragma warning(push)
13#pragma warning(disable:4244)
14#endif
15#include <boost/random/mersenne_twister.hpp>
16#include <boost/random/uniform_int_distribution.hpp>
17#if defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
18#pragma warning(pop)
19#endif
20
21void run_tests()
22{
23 boost::random::mt19937 gen;
24 boost::random::uniform_int_distribution<> dist(-10, 10);
25 std::list<int, boost::fast_pool_allocator<int> > l;
26
27 for(int i = 0; i < 100; ++i)
28 l.push_back(i);
29
30 for(int i = 0; i < 100000; ++i)
31 {
32 int val = dist(gen);
33 if(val < 0)
34 {
35 while(val && l.size())
36 {
37 l.pop_back();
38 ++i;
39 }
40 }
41 else
42 {
43 while(val)
44 {
45 l.push_back(val);
46 --val;
47 }
48 }
49 }
50}
51
52int main()
53{
54 std::list<boost::shared_ptr<boost::thread> > threads;
55 for(int i = 0; i < 10; ++i)
56 {
57 try{
58 threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(&run_tests)));
59 }
60 catch(const std::exception& e)
61 {
62 std::cerr << "<note>Thread creation failed with message: " << e.what() << "</note>" << std::endl;
63 }
64 }
65 std::list<boost::shared_ptr<boost::thread> >::const_iterator a(threads.begin()), b(threads.end());
66 while(a != b)
67 {
68 (*a)->join();
69 ++a;
70 }
71 return 0;
72}
73