MADNESS  version 0.9
Public Member Functions | Static Public Member Functions | Friends | List of all members
madness::ThreadBase Class Referenceabstract

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

#include <worldthread.h>

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

Public Member Functions

 ThreadBase ()
 Default constructor ... must invoke start() to actually begin the thread. More...
 
virtual ~ThreadBase ()
 
virtual void run ()=0
 You implement this to do useful work. More...
 
void start ()
 Start the thread running. 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 thread in ThreadPool (0,...,nthread-1) or -1 if not in ThreadPool. More...
 
int cancel () const
 Cancel this thread. More...
 

Static Public Member Functions

static void exit ()
 A thread can call this to terminate its execution. More...
 
static int num_hw_processors ()
 Get no. of actual hardware processors. More...
 
static void set_affinity_pattern (const bool bind[3], const int cpu[3])
 Specify the affinity pattern or how to bind threads to cpus. More...
 
static void set_affinity (int logical_id, int ind=-1)
 
static ThreadBasethis_thread ()
 

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

madness::ThreadBase::ThreadBase ( )
inline

Default constructor ... must invoke start() to actually begin the thread.

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

Member Function Documentation

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

Cancel this thread.

References get_id().

static void madness::ThreadBase::exit ( )
inlinestatic

A thread can call this to terminate its execution.

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

Get the pthread id of this thread (if running)

Referenced by cancel().

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

Get index of thread in ThreadPool (0,...,nthread-1) or -1 if not in ThreadPool.

int madness::ThreadBase::num_hw_processors ( )
static

Get no. of actual hardware processors.

References MADNESS_EXCEPTION.

Referenced by set_affinity_pattern().

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

You implement this to do useful work.

void madness::ThreadBase::set_affinity ( int  logical_id,
int  ind = -1 
)
static

Referenced by madness::initialize().

void madness::ThreadBase::set_affinity_pattern ( const bool  bind[3],
const int  cpu[3] 
)
static

Specify the affinity pattern or how to bind threads to cpus.

References num_hw_processors().

Referenced by madness::initialize().

void madness::ThreadBase::start ( )

Start the thread running.

References MADNESS_EXCEPTION.

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

static ThreadBase* madness::ThreadBase::this_thread ( )
inlinestatic

Friends And Related Function Documentation

friend class ThreadPool
friend

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