Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

thread.hpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // thread.hpp
  3. // ~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_THREAD_HPP
  11. #define ASIO_THREAD_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/detail/noncopyable.hpp"
  17. #include "asio/detail/thread.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. /// A simple abstraction for starting threads.
  21. /**
  22. * The asio::thread class implements the smallest possible subset of the
  23. * functionality of boost::thread. It is intended to be used only for starting
  24. * a thread and waiting for it to exit. If more extensive threading
  25. * capabilities are required, you are strongly advised to use something else.
  26. *
  27. * @par Thread Safety
  28. * @e Distinct @e objects: Safe.@n
  29. * @e Shared @e objects: Unsafe.
  30. *
  31. * @par Example
  32. * A typical use of asio::thread would be to launch a thread to run an
  33. * io_context's event processing loop:
  34. *
  35. * @par
  36. * @code asio::io_context io_context;
  37. * // ...
  38. * asio::thread t(boost::bind(&asio::io_context::run, &io_context));
  39. * // ...
  40. * t.join(); @endcode
  41. */
  42. class thread
  43. : private noncopyable
  44. {
  45. public:
  46. /// Start a new thread that executes the supplied function.
  47. /**
  48. * This constructor creates a new thread that will execute the given function
  49. * or function object.
  50. *
  51. * @param f The function or function object to be run in the thread. The
  52. * function signature must be: @code void f(); @endcode
  53. */
  54. template <typename Function>
  55. explicit thread(Function f)
  56. : impl_(f)
  57. {
  58. }
  59. /// Destructor.
  60. ~thread()
  61. {
  62. }
  63. /// Wait for the thread to exit.
  64. /**
  65. * This function will block until the thread has exited.
  66. *
  67. * If this function is not called before the thread object is destroyed, the
  68. * thread itself will continue to run until completion. You will, however,
  69. * no longer have the ability to wait for it to exit.
  70. */
  71. void join()
  72. {
  73. impl_.join();
  74. }
  75. private:
  76. detail::thread impl_;
  77. };
  78. } // namespace asio
  79. #include "asio/detail/pop_options.hpp"
  80. #endif // ASIO_THREAD_HPP