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)
5 #include <boost/smart_ptr/detail/spinlock.hpp>
6 #include <boost/smart_ptr/detail/lightweight_thread.hpp>
7 #include <boost/bind/bind.hpp>
8 #include <boost/core/lightweight_test.hpp>
11 static boost::detail::spinlock sp
= BOOST_DETAIL_SPINLOCK_INIT
;
15 for( int i
= 0; i
< n
; ++i
)
17 boost::detail::spinlock::scoped_lock
lock( sp
);
24 int const N
= 100000; // iterations
25 int const M
= 8; // threads
27 boost::detail::lw_thread_t th
[ M
] = {};
29 for( int i
= 0; i
< M
; ++i
)
31 boost::detail::lw_thread_create( th
[ i
], boost::bind( f
, N
) );
34 for( int i
= 0; i
< M
; ++i
)
36 boost::detail::lw_thread_join( th
[ i
] );
39 BOOST_TEST_EQ( count
, N
* M
);
41 return boost::report_errors();