MADNESS 0.10.1
madness::ThreadBase Class Referenceabstract

Simplified thread wrapper to hide pthread complexity. More...

#include <thread.h>

Inheritance diagram for madness::ThreadBase:

Public Member Functions

 ThreadBase ()
 Default constructor.
virtual ~ThreadBase ()
int cancel () const
 Cancel this thread.
const pthread_t & get_id () const
 Get the pthread id of this thread (if running).
int get_pool_thread_index () const
 Get index of this thread in ThreadPool.
virtual void run ()=0
 Function to be executed by the thread.
void start ()
 Start the thread running.

Static Public Member Functions

static void exit ()
 A thread can call this to terminate its execution.
static int num_hw_processors ()
 Get number of actual hardware processors.
static ThreadBase * this_thread ()

Private Member Functions

void set_pool_thread_index (int i)
 Sets the index of this thread within the pool.

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.

Static Private Attributes

static pthread_key_t thread_key
 Thread id key.

Friends

class ThreadPool

Detailed Description

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.

Constructor & Destructor Documentation

◆ ThreadBase()

madness::ThreadBase::ThreadBase ( )
inline

Default constructor.

Sets up the thread; however, start() must be invoked to actually begin the thread.

References pool_num.

Referenced by Peasant::Peasant(), Worker::Worker(), main(), and this_thread().

◆ ~ThreadBase()

virtual madness::ThreadBase::~ThreadBase ( )
inlinevirtual

Member Function Documentation

◆ cancel()

int madness::ThreadBase::cancel ( ) const
inline

Cancel this thread.

References get_id().

◆ delete_thread_key()

void madness::ThreadBase::delete_thread_key ( )
inlinestaticprivate
Todo
Brief description needed.

References thread_key.

Referenced by madness::ThreadPool::end().

◆ exit()

void madness::ThreadBase::exit ( )
inlinestatic

A thread can call this to terminate its execution.

◆ get_id()

const pthread_t & madness::ThreadBase::get_id ( ) const
inline

Get the pthread id of this thread (if running).

References id.

Referenced by cancel().

◆ get_pool_thread_index()

int madness::ThreadBase::get_pool_thread_index ( ) const
inline

Get index of this thread in ThreadPool.

Returns
(0,...,nthread-1) or -1 if not in the ThreadPool.

References pool_num.

Referenced by madness::profiling::TaskEventList::print_events().

◆ init_thread_key()

void madness::ThreadBase::init_thread_key ( )
inlinestaticprivate
Todo
Brief description needed.

References MADNESS_EXCEPTION, and thread_key.

Referenced by madness::ThreadPool::begin().

◆ main()

void * madness::ThreadBase::main ( void * self)
staticprivate
Todo
Brief description needed.
Todo
Descriptions needed.
Parameters
[in,out]selfDescription needed.
Returns
Description needed.

References ThreadBase(), madness::begin_papi_measurement(), e(), madness::end_papi_measurement(), madness::error(), MADNESS_EXCEPTION, pool_num, madness::print(), madness::set_thread_tag(), thread_key, and madness::ThreadTag_MADNESS.

Referenced by start().

◆ num_hw_processors()

int madness::ThreadBase::num_hw_processors ( )
static

Get number of actual hardware processors.

Returns
The number of hardward processors.

References MADNESS_EXCEPTION.

Referenced by madness::ThreadPool::default_nthread().

◆ run()

virtual void madness::ThreadBase::run ( )
pure virtual

Function to be executed by the thread.

Override this to do work.

Implemented in madness::Thread, Peasant, and Worker.

◆ set_pool_thread_index()

void madness::ThreadBase::set_pool_thread_index ( int i)
inlineprivate

Sets the index of this thread within the pool.

Todo
Verify documentation.
Parameters
[in]iThe index of this thread.

References pool_num.

◆ start()

void madness::ThreadBase::start ( )

Start the thread running.

References MADNESS_EXCEPTION, and main().

Referenced by Peasant::Peasant(), madness::Thread::Thread(), Worker::Worker(), and madness::Thread::start().

◆ this_thread()

ThreadBase * madness::ThreadBase::this_thread ( )
inlinestatic
Todo
Brief description needed.
Todo
Descriptions needed.
Returns
Description needed.

References ThreadBase(), and thread_key.

Referenced by madness::profiling::TaskEventList::print_events(), and madness::ThreadPool::run_task().

◆ ThreadPool

friend class ThreadPool
friend

References ThreadPool.

Referenced by ThreadPool.

Member Data Documentation

◆ id

pthread_t madness::ThreadBase::id
private
Todo
Brief description needed.

Referenced by get_id().

◆ pool_num

int madness::ThreadBase::pool_num
private

Stores index of thread in pool or -1.

Referenced by ThreadBase(), get_pool_thread_index(), main(), and set_pool_thread_index().

◆ thread_key

pthread_key_t madness::ThreadBase::thread_key
staticprivate

The documentation for this class was generated from the following files: