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

Private Member Functions

void run ()
 Invokes the function for this thread. More...
 

Private Attributes

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

Additional Inherited Members

- Static Public Member Functions inherited from madness::ThreadBase
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 ()
 

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: