lightweight_thread.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef BOOST_SMART_PTR_DETAIL_LIGHTWEIGHT_THREAD_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_DETAIL_LIGHTWEIGHT_THREAD_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. // boost/detail/lightweight_thread.hpp
  8. //
  9. // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
  10. // Copyright (c) 2008, 2018 Peter Dimov
  11. //
  12. // Distributed under the Boost Software License, Version 1.0.
  13. // See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt
  15. //
  16. //
  17. // typedef /*...*/ lw_thread_t; // as pthread_t
  18. // template<class F> int lw_thread_create( lw_thread_t & th, F f );
  19. // void lw_thread_join( lw_thread_t th );
  20. #include <thread>
  21. #include <exception>
  22. namespace boost
  23. {
  24. namespace detail
  25. {
  26. using lw_thread_t = std::thread*;
  27. template<class F> int lw_thread_create( lw_thread_t& th, F f )
  28. {
  29. try
  30. {
  31. th = new std::thread( f );
  32. return 0;
  33. }
  34. catch( std::exception const& )
  35. {
  36. return -1;
  37. }
  38. }
  39. void lw_thread_join( lw_thread_t th )
  40. {
  41. th->join();
  42. delete th;
  43. }
  44. } // namespace detail
  45. } // namespace boost
  46. #endif // #ifndef BOOST_SMART_PTR_DETAIL_LIGHTWEIGHT_THREAD_HPP_INCLUDED