MADNESS
0.10.1
|
Simplified thread wrapper to hide pthread complexity. More...
#include <thread.h>
Public Member Functions | |
ThreadBase () | |
Default constructor. More... | |
virtual | ~ThreadBase () |
int | cancel () const |
Cancel this thread. More... | |
const pthread_t & | get_id () const |
Get the pthread id of this thread (if running). More... | |
int | get_pool_thread_index () const |
Get index of this thread in ThreadPool . More... | |
virtual void | run ()=0 |
Function to be executed by the thread. More... | |
void | start () |
Start the thread running. More... | |
Static Public Member Functions | |
static void | exit () |
A thread can call this to terminate its execution. More... | |
static int | num_hw_processors () |
Get number of actual hardware processors. More... | |
static ThreadBase * | this_thread () |
Private Member Functions | |
void | set_pool_thread_index (int i) |
Sets the index of this thread within the pool. More... | |
Static Private Member Functions | |
static void | delete_thread_key () |
static void | init_thread_key () |
static void * | main (void *self) |
Private Attributes | |
pthread_t | id |
int | pool_num |
Stores index of thread in pool or -1. More... | |
Static Private Attributes | |
static pthread_key_t | thread_key |
Thread id key. More... | |
Friends | |
class | ThreadPool |
Simplified thread wrapper to hide pthread complexity.
If the thread is using any of the object state, you cannot delete the object until the thread has terminated.
The cleanest solution is to put the object on the heap and have the run method delete this
at its end.
|
inline |
Default constructor.
Sets up the thread; however, start()
must be invoked to actually begin the thread.
|
inlinevirtual |
|
inline |
Cancel this thread.
References get_id().
|
inlinestaticprivate |
|
inlinestatic |
A thread can call this to terminate its execution.
|
inline |
|
inline |
Get index of this thread in ThreadPool
.
ThreadPool
. References pool_num.
Referenced by madness::profiling::TaskEventList::print_events().
|
inlinestaticprivate |
References MADNESS_EXCEPTION, and thread_key.
Referenced by madness::ThreadPool::begin().
|
staticprivate |
[in,out] | self | Description needed. |
References madness::begin_papi_measurement(), e(), madness::end_papi_measurement(), madness::error(), MADNESS_EXCEPTION, pool_num, madness::print(), run(), madness::set_thread_tag(), thread_key, and madness::ThreadTag_MADNESS.
Referenced by start().
|
static |
Get number of actual hardware processors.
References MADNESS_EXCEPTION.
Referenced by madness::ThreadPool::default_nthread().
|
pure virtual |
Function to be executed by the thread.
Override this to do work.
Implemented in madness::Thread, Peasant, and Worker.
Referenced by main().
|
inlineprivate |
Sets the index of this thread within the pool.
[in] | i | The index of this thread. |
References pool_num.
Referenced by madness::ThreadPool::ThreadPool().
void madness::ThreadBase::start | ( | ) |
Start the thread running.
References MADNESS_EXCEPTION, and main().
Referenced by madness::Thread::Thread(), and madness::Thread::start().
|
inlinestatic |
References thread_key.
Referenced by madness::profiling::TaskEventList::print_events(), and madness::ThreadPool::run_task().
|
friend |
|
private |
Stores index of thread in pool or -1.
Referenced by get_pool_thread_index(), main(), and set_pool_thread_index().
|
staticprivate |
Thread id key.
Referenced by madness::ThreadPool::ThreadPool(), delete_thread_key(), init_thread_key(), main(), and this_thread().