MADNESS  0.10.1
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
madness::ThreadBase Class Referenceabstract

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

#include <thread.h>

Inheritance diagram for madness::ThreadBase:
Inheritance graph
[legend]

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 ThreadBasethis_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
 

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.

◆ ~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()

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

References thread_key.

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

◆ exit()

static 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()

static 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 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().

◆ 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.

Referenced by main().

◆ 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.

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

◆ start()

void madness::ThreadBase::start ( )

Start the thread running.

References MADNESS_EXCEPTION, and main().

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

◆ this_thread()

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

References thread_key.

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

Friends And Related Function Documentation

◆ ThreadPool

friend class ThreadPool
friend

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 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: