![]() |
Kea
1.5.0
|
A separate thread. More...
#include <thread.h>
Inheritance diagram for isc::util::thread::Thread:Classes | |
| class | Impl |
| class | UncaughtException |
| There's an uncaught exception in a thread. More... | |
Public Member Functions | |
| Thread (const boost::function< void()> &main) | |
| Create and start a thread. More... | |
| ~Thread () | |
| Destructor. More... | |
| void | wait () |
| Wait for the thread to terminate. More... | |
A separate thread.
A thread of execution. When created, starts running in the background. You can wait for it then or just forget it ever existed and leave it live peacefully.
The interface is minimalist for now. We may need to extend it later.
| isc::util::thread::Thread::Thread | ( | const boost::function< void()> & | main | ) |
Create and start a thread.
Create a new thread and run body inside it.
If you need to pass parameters to body, or return some result, you may just want to use boost::bind or alike to store them within the body functor.
The body should terminate by exiting the function. If it throws, it is considered an error. You should generally catch any exceptions form within there and handle them somehow.
| main | The code to run inside the thread. |
| std::bad_alloc | if allocation of the new thread or other resources fails. |
| isc::InvalidOperation | for other errors (should not happen). |
Definition at line 125 of file thread.cc.
References isc::ha::impl, isc_throw, main(), and isc::util::thread::Thread::Impl::run().
Here is the call graph for this function:| isc::util::thread::Thread::~Thread | ( | ) |
Destructor.
It is completely legitimate to destroy the thread without calling wait() before. In such case, the thread will just live on until it terminates. However, if the thread dies due to exception, for example, it's up to you to detect that, no error is reported from this class.
| isc::InvalidOperation | in the rare case of OS reporting a problem. This should not happen unless you messed up with the raw thread by the low-level API. |
Definition at line 144 of file thread.cc.
References isc::util::thread::Thread::Impl::done(), and isc::util::thread::Thread::Impl::tid_.
Here is the call graph for this function:| void isc::util::thread::Thread::wait | ( | ) |
Wait for the thread to terminate.
Waits until the thread terminates. Must be called at most once.
| isc::InvalidOperation | if the OS API returns error. This usually mean a programmer error (like two threads trying to wait on each other). |
| isc::InvalidOperation | calling wait a second time. |
| UncaughtException | if the thread terminated by throwing an exception instead of just returning from the function. |
Definition at line 156 of file thread.cc.
References isc::util::thread::Thread::Impl::done(), isc::util::thread::Thread::Impl::exception_, isc::util::thread::Thread::Impl::exception_text_, isc_throw, and isc::util::thread::Thread::Impl::tid_.
Here is the call graph for this function: