libeblearntools
|
A thread abstraction class. More...
#include <thread.h>
Public Member Functions | |
thread (mutex *outmutex=NULL, const char *name="Thread", bool sync=true) | |
int | start () |
Start the thread. | |
void | stop (long wait_seconds=0) |
void | ask_stop () |
bool | finished () |
Return true if thread has finished executing. | |
std::string & | name () |
Return name of this thread. | |
std::ostream & | get_mout () |
Return a reference this thread's output stream. | |
std::ostream & | get_merr () |
Return a reference this thread's output error stream. | |
Protected Member Functions | |
void | run () |
virtual void | execute ()=0 |
Static Protected Member Functions | |
static void * | entrypoint (void *pthis) |
Protected Attributes | |
bool | _stop |
std::string | _name |
mutex_ostream | mutout |
Name of this thread. | |
mutex_ostream | muterr |
ostream & | mout |
ostream & | merr |
A thread abstraction class.
ebl::thread::thread | ( | mutex * | outmutex = NULL , |
const char * | name = "Thread" , |
||
bool | sync = true |
||
) |
outmutex | A mutex used to synchronize threads outputs/ To synchronize all threads, give the same mutex to each of them. |
sync | If true, synchronize outputs between threads, using outmutex, otherwise use regular unsynced outputs. |
void ebl::thread::ask_stop | ( | ) |
Tell the thread it should stop. The thread might be busy finishing some task, so this only tells it to quit when it is finished. One can check if the thread is finished with the finished() method.
void ebl::thread::stop | ( | long | wait_seconds = 0 | ) |
Stop the thread. If wait_seconds is zero, stop the thread right now, otherwise wait until the thread has finished its current task or force it to exit if it's not finished after wait_seconds seconds.