Privacy
An open-source, flexible 3D physical simulation framework
mars::utils::Thread Class Referenceabstract

#include <Thread.h>

Public Member Functions

 Thread ()
 
virtual ~Thread ()
 
void start ()
 Starts the execution of this Thread. More...
 
void cancel (bool block=false)
 Tries to cancel the Thread. More...
 
void setCancellationPoint ()
 Adds a cancellation point to your run method. More...
 
bool wait ()
 stops execution until the thread has finished. More...
 
bool join ()
 
bool wait (unsigned long timeoutMilliseconds)
 puts the Thread to sleep for a specified amount of time. More...
 
bool isRunning () const
 returns true if the Thread is running. More...
 
bool isFinished () const
 
void setStackSize (std::size_t stackSize)
 
std::size_t getStackSize () const
 
bool isCurrentThread () const
 

Static Public Member Functions

static ThreadgetCurrentThread ()
 
static void cancelAll (bool block=false)
 

Protected Member Functions

virtual void run ()=0
 The thread will execute this method once it has been started . More...
 

Static Protected Member Functions

static void msleep (unsigned long msec)
 causes the current thread to sleep for More...
 

Private Member Functions

 Thread (const Thread &)
 
Threadoperator= (const Thread &)
 

Static Private Member Functions

static void * runHelper (void *context)
 
static void cleanupHandler (void *context)
 

Private Attributes

PthreadThreadWrappermyThread
 
std::size_t myStackSize
 
bool running
 
bool finished
 

Static Private Attributes

static Mutex threadListMutex
 
static std::list< Thread * > threads
 

Detailed Description

Definition at line 39 of file Thread.h.

Constructor & Destructor Documentation

◆ Thread() [1/2]

mars::utils::Thread::Thread ( )

Definition at line 60 of file Thread.cpp.

◆ ~Thread()

mars::utils::Thread::~Thread ( )
virtual

Definition at line 75 of file Thread.cpp.

◆ Thread() [2/2]

mars::utils::Thread::Thread ( const Thread )
private

Member Function Documentation

◆ cancel()

void mars::utils::Thread::cancel ( bool  block = false)

Tries to cancel the Thread.

Parameters
blockIf true cancel will only return when the Thread stopped. The Thread can only be canceled at certain cancellation points. Many IO related system calls are cancellation points and so is Thread::wait. You can manually add cancellation points to you run method by calling Thread::setCancelationPoint().
See also
setCancellationPoint()

Definition at line 139 of file Thread.cpp.

◆ cancelAll()

void mars::utils::Thread::cancelAll ( bool  block = false)
static

Definition at line 205 of file Thread.cpp.

◆ cleanupHandler()

void mars::utils::Thread::cleanupHandler ( void *  context)
staticprivate

Definition at line 133 of file Thread.cpp.

◆ getCurrentThread()

Thread * mars::utils::Thread::getCurrentThread ( )
static

Definition at line 189 of file Thread.cpp.

◆ getStackSize()

std::size_t mars::utils::Thread::getStackSize ( ) const

Definition at line 180 of file Thread.cpp.

◆ isCurrentThread()

bool mars::utils::Thread::isCurrentThread ( ) const

Definition at line 184 of file Thread.cpp.

◆ isFinished()

bool mars::utils::Thread::isFinished ( ) const
See also
isRunning()

Definition at line 176 of file Thread.cpp.

◆ isRunning()

bool mars::utils::Thread::isRunning ( ) const

returns true if the Thread is running.

returns true if the Thread was started and has not terminated (i.e. the run method has not returned yet) and was not canceled. returns false otherwise.

See also
isFinished()

Definition at line 172 of file Thread.cpp.

◆ join()

bool mars::utils::Thread::join ( )

Definition at line 160 of file Thread.cpp.

◆ msleep()

void mars::utils::Thread::msleep ( unsigned long  msec)
staticprotected

causes the current thread to sleep for

  • msec millisecond.

Definition at line 201 of file Thread.cpp.

◆ operator=()

Thread& mars::utils::Thread::operator= ( const Thread )
private

◆ run()

virtual void mars::utils::Thread::run ( )
protectedpure virtual

◆ runHelper()

void * mars::utils::Thread::runHelper ( void *  context)
staticprivate

Definition at line 119 of file Thread.cpp.

◆ setCancellationPoint()

void mars::utils::Thread::setCancellationPoint ( )

Adds a cancellation point to your run method.

See also
cancel

Definition at line 148 of file Thread.cpp.

◆ setStackSize()

void mars::utils::Thread::setStackSize ( std::size_t  stackSize)

Definition at line 88 of file Thread.cpp.

◆ start()

void mars::utils::Thread::start ( )

Starts the execution of this Thread.

This will start new thread in which the run method will be executed. This method will return as soon as the thread has been set up.

See also
run(), wait(), wait(unsigned long)

Definition at line 103 of file Thread.cpp.

◆ wait() [1/2]

bool mars::utils::Thread::wait ( )

stops execution until the thread has finished.

See also
wait(unsigned long), cancel()

Definition at line 152 of file Thread.cpp.

◆ wait() [2/2]

bool mars::utils::Thread::wait ( unsigned long  timeoutMilliseconds)

puts the Thread to sleep for a specified amount of time.

Parameters
timeoutMillisecondsThe time the Thread shall sleep in milliseconds
See also
wait(), cancel()

Definition at line 164 of file Thread.cpp.

Member Data Documentation

◆ finished

bool mars::utils::Thread::finished
private

Definition at line 130 of file Thread.h.

◆ myStackSize

std::size_t mars::utils::Thread::myStackSize
private

Definition at line 128 of file Thread.h.

◆ myThread

PthreadThreadWrapper* mars::utils::Thread::myThread
private

Definition at line 126 of file Thread.h.

◆ running

bool mars::utils::Thread::running
private

Definition at line 129 of file Thread.h.

◆ threadListMutex

Mutex mars::utils::Thread::threadListMutex
staticprivate

Definition at line 131 of file Thread.h.

◆ threads

std::list< Thread * > mars::utils::Thread::threads
staticprivate

Definition at line 132 of file Thread.h.


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