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