]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/test/storage_adaptor_threaded_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / histogram / test / storage_adaptor_threaded_test.cpp
1 // Copyright 2019 Hans Dembinski
2 //
3 // Distributed under the 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/core/lightweight_test.hpp>
8 #include <boost/histogram/accumulators/count.hpp>
9 #include <boost/histogram/accumulators/ostream.hpp>
10 #include <boost/histogram/storage_adaptor.hpp>
11 #include "throw_exception.hpp"
12
13 #include <array>
14 #include <deque>
15 #include <map>
16 #include <thread>
17 #include <unordered_map>
18 #include <vector>
19
20 using namespace boost::histogram;
21
22 constexpr auto n_fill = 1000000;
23
24 template <class T>
25 void tests() {
26 {
27 storage_adaptor<T> s;
28 s.reset(1);
29
30 auto fill = [&s]() {
31 for (unsigned i = 0; i < n_fill; ++i) {
32 ++s[0];
33 s[0] += 1;
34 }
35 };
36
37 std::thread t1(fill);
38 std::thread t2(fill);
39 std::thread t3(fill);
40 std::thread t4(fill);
41 t1.join();
42 t2.join();
43 t3.join();
44 t4.join();
45
46 BOOST_TEST_EQ(s[0], 4 * 2 * n_fill);
47 }
48 }
49
50 int main() {
51 using ts_int = accumulators::count<int, true>;
52 tests<std::vector<ts_int>>();
53 tests<std::array<ts_int, 100>>();
54 tests<std::deque<ts_int>>();
55 // stdlib maps are not thread-safe and not supported
56
57 return boost::report_errors();
58 }