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 <iostream> 9 #include <boost/pool/pool_alloc.hpp> 10 #include <boost/thread.hpp> 11 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1600) 12 #pragma warning(push) 13 #pragma warning(disable: 4244) 14 // ..\..\boost/random/uniform_int_distribution.hpp(171) : 15 // warning C4127: conditional expression is constant 16 #pragma warning(disable: 4127) 17 // ..\..\boost/random/detail/polynomial.hpp(315) : 18 // warning C4267: 'argument' : conversion from 'size_t' 19 // to 'int', possible loss of data 20 #pragma warning(disable: 4267) 21 #endif 22 #include <boost/random/mersenne_twister.hpp> 23 #include <boost/random/uniform_int_distribution.hpp> 24 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1600) 25 #pragma warning(pop) 26 #endif 27 run_tests()28void run_tests() 29 { 30 boost::random::mt19937 gen; 31 boost::random::uniform_int_distribution<> dist(-10, 10); 32 std::list<int, boost::fast_pool_allocator<int> > l; 33 34 for(int i = 0; i < 100; ++i) 35 l.push_back(i); 36 37 for(int i = 0; i < 20000; ++i) 38 { 39 int val = dist(gen); 40 if(val < 0) 41 { 42 while(val && l.size()) 43 { 44 l.pop_back(); 45 ++val; 46 } 47 } 48 else 49 { 50 while(val) 51 { 52 l.push_back(val); 53 --val; 54 } 55 } 56 } 57 } 58 main()59int main() 60 { 61 std::list<boost::shared_ptr<boost::thread> > threads; 62 for(int i = 0; i < 10; ++i) 63 { 64 try{ 65 threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(&run_tests))); 66 } 67 catch(const std::exception& e) 68 { 69 std::cerr << "<note>Thread creation failed with message: " << e.what() << "</note>" << std::endl; 70 } 71 } 72 std::list<boost::shared_ptr<boost::thread> >::const_iterator a(threads.begin()), b(threads.end()); 73 while(a != b) 74 { 75 (*a)->join(); 76 ++a; 77 } 78 return 0; 79 } 80 81