]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // Copyright 2018, 2020 Peter Dimov |
2 | // Distributed under the Boost Software License, Version 1.0. | |
3 | // https://www.boost.org/LICENSE_1_0.txt) | |
4 | ||
5 | #include <boost/smart_ptr/detail/spinlock_pool.hpp> | |
6 | #include <boost/smart_ptr/detail/lightweight_thread.hpp> | |
7 | #include <boost/bind/bind.hpp> | |
8 | #include <boost/core/lightweight_test.hpp> | |
9 | ||
10 | static int count = 0; | |
11 | ||
12 | void f( int n ) | |
13 | { | |
14 | for( int i = 0; i < n; ++i ) | |
15 | { | |
16 | boost::detail::spinlock_pool<0>::scoped_lock lock( &count ); | |
17 | ++count; | |
18 | } | |
19 | } | |
20 | ||
21 | int main() | |
22 | { | |
23 | int const N = 100000; // iterations | |
24 | int const M = 8; // threads | |
25 | ||
26 | boost::detail::lw_thread_t th[ M ] = {}; | |
27 | ||
28 | for( int i = 0; i < M; ++i ) | |
29 | { | |
30 | boost::detail::lw_thread_create( th[ i ], boost::bind( f, N ) ); | |
31 | } | |
32 | ||
33 | for( int i = 0; i < M; ++i ) | |
34 | { | |
35 | boost::detail::lw_thread_join( th[ i ] ); | |
36 | } | |
37 | ||
38 | BOOST_TEST_EQ( count, N * M ); | |
39 | ||
40 | return boost::report_errors(); | |
41 | } |