]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/test/accumulators_count_thread_safe_test.cpp
1 // Copyright 2015-2018 Hans Dembinski
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)
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/histogram/accumulators/count.hpp>
9 #include <boost/histogram/accumulators/ostream.hpp>
12 #include "throw_exception.hpp"
13 #include "utility_str.hpp"
15 using namespace boost::histogram
;
16 using namespace std::literals
;
18 constexpr int N
= 10000;
23 for (int i
= 0; i
< N
; ++i
) f();
26 std::thread
a(g
), b(g
), c(g
), d(g
);
35 using ts_t
= accumulators::count
<T
, true>;
40 BOOST_TEST_EQ(i
, static_cast<T
>(0));
46 BOOST_TEST_EQ(i
, static_cast<T
>(1001));
47 BOOST_TEST_EQ(str(i
), "1001"s
);
51 BOOST_TEST_EQ(ts_t
{} += ts_t
{}, ts_t
{});
54 BOOST_TEST_EQ((ts_t
{} += ts_t
{2}), (ts_t
{2}));
59 parallel([&]() { ++t
; });
60 BOOST_TEST_EQ(t
, static_cast<T
>(4 * N
));
63 // operator+= with value
66 parallel([&]() { t
+= 2; });
67 BOOST_TEST_EQ(t
, static_cast<T
>(8 * N
));
70 // operator+= with another thread-safe
74 parallel([&]() { t
+= u
; });
75 BOOST_TEST_EQ(t
, static_cast<T
>(8 * N
));
83 // copy and assignment from other thread-safe
85 accumulators::count
<char, true> r
{1};
86 accumulators::count
<int, true> a
{r
}, b
;
92 return boost::report_errors();