MADNESS 0.10.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members

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

#include <thread.h>

Inheritance diagram for madness::Thread:
Inheritance graph
[legend]
Collaboration diagram for madness::Thread:
Collaboration graph
[legend]

Public Member Functions

 Thread ()
 Default constructor.
 
 Thread (void *(*f)(void *), void *args=nullptr)
 Create a thread and start it running f(args).
 
virtual ~Thread ()=default
 
void start (void *(*f)(void *), void *args=nullptr)
 Start the thread by running f(args).
 
- Public Member Functions inherited from madness::ThreadBase
 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.
 
void start ()
 Start the thread running.
 

Private Member Functions

void run ()
 Invokes the function for this thread.
 

Private Attributes

void * args
 The arguments passed to this thread for execution.
 
void *(* f )(void *)
 The function called for executing this thread.
 

Additional Inherited Members

- Static Public Member Functions inherited from madness::ThreadBase
static void exit ()
 A thread can call this to terminate its execution.
 
static int num_hw_processors ()
 Get number of actual hardware processors.
 
static ThreadBasethis_thread ()
 

Detailed Description

Simplified thread wrapper to hide pthread complexity.

Constructor & Destructor Documentation

◆ Thread() [1/2]

madness::Thread::Thread ( )
inline

Default constructor.

start() must be invoked to actually execute the thread.

◆ Thread() [2/2]

madness::Thread::Thread ( void *(*)(void *)  f,
void *  args = nullptr 
)
inline

Create a thread and start it running f(args).

Parameters
[in]fThe function to be called.
[in,out]argsThe arguments to the function.

References madness::ThreadBase::start().

◆ ~Thread()

virtual madness::Thread::~Thread ( )
virtualdefault

Member Function Documentation

◆ run()

void madness::Thread::run ( )
inlineprivatevirtual

Invokes the function for this thread.

Implements madness::ThreadBase.

References args, and f.

◆ start()

void madness::Thread::start ( void *(*)(void *)  f,
void *  args = nullptr 
)
inline

Start the thread by running f(args).

Parameters
[in]fThe function to be called.
[in,out]argsThe arguments to the function.

References args, f, and madness::ThreadBase::start().

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

Member Data Documentation

◆ args

void* madness::Thread::args
private

The arguments passed to this thread for execution.

Referenced by run(), and start().

◆ f

void *(* madness::Thread::f) (void *)
private

The function called for executing this thread.

Todo:
should we replace this by a std::function?

Referenced by run(), and start().


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