1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Copyright John Maddock, 2021
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/math/tools/config.hpp>
#if !defined(BOOST_MATH_NO_THREAD_LOCAL_WITH_NON_TRIVIAL_TYPES) && defined(BOOST_HAS_THREADS)
#include <vector>
#include <atomic>
#include <thread>
#include <random>
#include <algorithm>
#include <iostream>
std::atomic<int> counter{ 0 };
void thread_proc()
{
static thread_local std::vector<double> list;
std::default_random_engine rnd;
std::uniform_real_distribution<> dist;
for (unsigned i = 0; i < 1000; ++i)
{
list.push_back(dist(rnd));
++counter;
}
std::sort(list.begin(), list.end());
}
int main()
{
std::thread f1(thread_proc);
std::thread f2(thread_proc);
std::thread f3(thread_proc);
std::thread f4(thread_proc);
std::thread f5(thread_proc);
std::thread f6(thread_proc);
f1.join();
f2.join();
f3.join();
f4.join();
f5.join();
f6.join();
std::cout << "Counter value was: " << counter << std::endl;
return counter - 6000;
}
#else
int main() { return 0; }
#endif
|