A simple abstraction for starting threads. * The asio::thread class implements the smallest possible subset of the * functionality of boost::thread. It is intended to be used only for starting * a thread and waiting for it to exit. If more extensive threading * capabilities are required, you are strongly advised to use something else. * * @par Thread Safety * @e Distinct @e objects: Safe.@n
| 46 | * t.join(); @endcode |
| 47 | */ |
| 48 | class thread |
| 49 | : private noncopyable |
| 50 | { |
| 51 | public: |
| 52 | /// Start a new thread that executes the supplied function. |
| 53 | /** |
| 54 | * This constructor creates a new thread that will execute the given function |
| 55 | * or function object. |
| 56 | * |
| 57 | * @param f The function or function object to be run in the thread. The |
| 58 | * function signature must be: @code void f(); @endcode |
| 59 | */ |
| 60 | template <typename Function> |
| 61 | explicit thread(Function f) |
| 62 | : impl_(f) |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | /// Destructor. |
| 67 | ~thread() |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | /// Wait for the thread to exit. |
| 72 | /** |
| 73 | * This function will block until the thread has exited. |
| 74 | * |
| 75 | * If this function is not called before the thread object is destroyed, the |
| 76 | * thread itself will continue to run until completion. You will, however, |
| 77 | * no longer have the ability to wait for it to exit. |
| 78 | */ |
| 79 | void join() |
| 80 | { |
| 81 | impl_.join(); |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | detail::thread impl_; |
| 86 | }; |
| 87 | |
| 88 | } // namespace asio |
| 89 |
no outgoing calls