/* Copyright (C) 2011 John Maddock * * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */ #include #include #if defined(BOOST_MSVC) && (BOOST_MSVC == 1400) #pragma warning(push) #pragma warning(disable:4244) #endif #include #include #if defined(BOOST_MSVC) && (BOOST_MSVC == 1400) #pragma warning(pop) #endif void run_tests() { boost::random::mt19937 gen; boost::random::uniform_int_distribution<> dist(-10, 10); std::list > l; for(int i = 0; i < 100; ++i) l.push_back(i); for(int i = 0; i < 100000; ++i) { int val = dist(gen); if(val < 0) { while(val && l.size()) { l.pop_back(); ++i; } } else { while(val) { l.push_back(val); --val; } } } } int main() { std::list > threads; for(int i = 0; i < 10; ++i) { try{ threads.push_back(boost::shared_ptr(new boost::thread(&run_tests))); } catch(const std::exception& e) { std::cerr << "Thread creation failed with message: " << e.what() << "" << std::endl; } } std::list >::const_iterator a(threads.begin()), b(threads.end()); while(a != b) { (*a)->join(); ++a; } return 0; }