lw_thread_test.cpp 677 B

123456789101112131415161718192021222324252627282930313233343536
  1. // lw_thread_test.cpp
  2. //
  3. // Copyright 2018 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. #include <boost/detail/lightweight_thread.hpp>
  6. #include <boost/detail/lightweight_test.hpp>
  7. #include <boost/smart_ptr/detail/atomic_count.hpp>
  8. boost::detail::atomic_count count( 0 );
  9. void f()
  10. {
  11. ++count;
  12. }
  13. int main()
  14. {
  15. int const N = 4;
  16. boost::detail::lw_thread_t th[ N ] = {};
  17. for( int i = 0; i < N; ++i )
  18. {
  19. boost::detail::lw_thread_create( th[ i ], f );
  20. }
  21. for( int i = 0; i < N; ++i )
  22. {
  23. boost::detail::lw_thread_join( th[ i ] );
  24. }
  25. BOOST_TEST_EQ( count, N );
  26. return boost::report_errors();
  27. }