Main MRPT website > C++ reference
MRPT logo
Classes | Namespaces | Enumerations | Functions
Threads (in #include <mrpt/system/threads.h>)

Detailed Description

Collaboration diagram for Threads (in #include <mrpt/system/threads.h>):

Classes

struct  mrpt::system::TThreadHandle
 This structure contains the information needed to interface the threads API on each platform: More...
 

Namespaces

 mrpt::system::detail
 Auxiliary classes used internally to MRPT.
 

Enumerations

enum  mrpt::system::TProcessPriority { mrpt::system::ppIdle = 0, mrpt::system::ppNormal, mrpt::system::ppHigh, mrpt::system::ppVeryHigh }
 The type for cross-platform process (application) priorities. More...
 
enum  mrpt::system::TThreadPriority {
  mrpt::system::tpLowests =-15, mrpt::system::tpLower = -2, mrpt::system::tpLow = -1, mrpt::system::tpNormal = 0,
  mrpt::system::tpHigh = 1, mrpt::system::tpHigher = 2, mrpt::system::tpHighest = 15
}
 The type for cross-platform thread priorities. More...
 

Functions

template<typename T >
TThreadHandle mrpt::system::createThread (void(*func)(T), T param)
 Creates a new thread from a function (or static method) with one generic parameter. More...
 
template<typename T >
TThreadHandle mrpt::system::createThreadRef (void(*func)(T &), T &param)
 
TThreadHandle mrpt::system::createThread (void(*func)(void))
 
template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethod (CLASS *obj, void(CLASS::*func)(PARAM), PARAM param)
 Creates a new thread running a non-static method (so it will have access to "this") from another method of the same class - with one generic parameter. More...
 
template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethodRef (CLASS *obj, void(CLASS::*func)(PARAM), PARAM &param)
 
template<typename CLASS >
TThreadHandle mrpt::system::createThreadFromObjectMethod (CLASS *obj, void(CLASS::*func)(void))
 
void BASE_IMPEXP mrpt::system::joinThread (const TThreadHandle &threadHandle)
 Waits until the given thread ends. More...
 
unsigned long BASE_IMPEXP mrpt::system::getCurrentThreadId () MRPT_NO_THROWS
 Returns the ID of the current thread. More...
 
TThreadHandle BASE_IMPEXP mrpt::system::getCurrentThreadHandle () MRPT_NO_THROWS
 Returns a handle to the current thread. More...
 
void BASE_IMPEXP mrpt::system::exitThread () MRPT_NO_THROWS
 Explicit close of the current (running) thread. More...
 
void BASE_IMPEXP mrpt::system::getCurrentThreadTimes (time_t &creationTime, time_t &exitTime, double &cpuTime)
 Returns the creation and exit times of the current thread and its CPU time consumed. More...
 
void BASE_IMPEXP mrpt::system::changeThreadPriority (const TThreadHandle &threadHandle, TThreadPriority priority)
 Change the priority of the given thread. More...
 
void BASE_IMPEXP mrpt::system::terminateThread (TThreadHandle &threadHandle) MRPT_NO_THROWS
 Terminate a thread, giving it no choice to delete objects, etc (use only as a last resource) More...
 
void BASE_IMPEXP mrpt::system::changeCurrentProcessPriority (TProcessPriority priority)
 Change the priority of the given process (it applies to all the threads, plus independent modifiers for each thread). More...
 
unsigned int BASE_IMPEXP mrpt::system::getNumberOfProcessors ()
 Return the number of processors ("cores"), or 1 if it cannot be determined. More...
 
void BASE_IMPEXP mrpt::system::sleep (int time_ms) MRPT_NO_THROWS
 An OS-independent method for sending the current thread to "sleep" for a given period of time. More...
 
bool BASE_IMPEXP mrpt::system::launchProcess (const std::string &command)
 Executes the given command (which may contain a program + arguments), and waits until it finishes. More...
 

Enumeration Type Documentation

◆ TProcessPriority

The type for cross-platform process (application) priorities.

See also
changeCurrentProcessPriority
Enumerator
ppIdle 
ppNormal 
ppHigh 
ppVeryHigh 

Definition at line 96 of file threads.h.

◆ TThreadPriority

The type for cross-platform thread priorities.

See also
changeThreadPriority
Enumerator
tpLowests 
tpLower 
tpLow 
tpNormal 
tpHigh 
tpHigher 
tpHighest 

Definition at line 106 of file threads.h.

Function Documentation

◆ changeCurrentProcessPriority()

void BASE_IMPEXP mrpt::system::changeCurrentProcessPriority ( TProcessPriority  priority)

Change the priority of the given process (it applies to all the threads, plus independent modifiers for each thread).

See also
createThread, changeThreadPriority

◆ changeThreadPriority()

void BASE_IMPEXP mrpt::system::changeThreadPriority ( const TThreadHandle threadHandle,
TThreadPriority  priority 
)

Change the priority of the given thread.

See also
createThread, changeCurrentProcessPriority

◆ createThread() [1/2]

template<typename T >
TThreadHandle mrpt::system::createThread ( void(*)(T)  func,
param 
)
inline

Creates a new thread from a function (or static method) with one generic parameter.

This function creates, and start, a new thread running some code given by a function. The thread function should end by returning as normal.

Parameters
funcThe function with the code to run in the thread.
paramThe parameter to be passed to the new thread function.
Returns
A structure that represents the thread (it contains its ID and, in Windows, its HANDLE).
Exceptions
std::exceptionIf the operation fails
See also
createThreadFromObjectMethod, joinThread, changeThreadPriority

Definition at line 207 of file threads.h.

References mrpt::system::detail::ThreadCreateFunctor< T >::createThread().

◆ createThread() [2/2]

TThreadHandle mrpt::system::createThread ( void(*)(void)  func)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 215 of file threads.h.

References mrpt::system::detail::ThreadCreateFunctorNoParams::createThread().

◆ createThreadFromObjectMethod() [1/2]

template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethod ( CLASS *  obj,
void(CLASS::*)(PARAM)  func,
PARAM  param 
)
inline

Creates a new thread running a non-static method (so it will have access to "this") from another method of the same class - with one generic parameter.

This function creates, and start, a new thread running some code given by a function. The thread function should end by returning as normal. Example of usage:

class MyClass {
public:
void myThread(int n);
void someMethod() {
createThreadFromObjectMethod(this, &MyClass::myThread, 123 );
....
}
};
Parameters
funcThe function with the code to run in the thread.
paramThe parameter to be passed to the new thread function.
Returns
A structure that represents the thread (it contains its ID and, in Windows, its HANDLE).
Exceptions
std::exceptionIf the operation fails
See also
createThread, joinThread, changeThreadPriority

Definition at line 242 of file threads.h.

References mrpt::system::detail::ThreadCreateObjectFunctor< CLASS, PARAM >::createThread().

◆ createThreadFromObjectMethod() [2/2]

template<typename CLASS >
TThreadHandle mrpt::system::createThreadFromObjectMethod ( CLASS *  obj,
void(CLASS::*)(void)  func 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 252 of file threads.h.

References mrpt::system::detail::ThreadCreateObjectFunctorNoParams< CLASS >::createThread().

◆ createThreadFromObjectMethodRef()

template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethodRef ( CLASS *  obj,
void(CLASS::*)(PARAM)  func,
PARAM &  param 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 247 of file threads.h.

References mrpt::system::detail::ThreadCreateObjectFunctor< CLASS, PARAM >::createThread().

◆ createThreadRef()

template<typename T >
TThreadHandle mrpt::system::createThreadRef ( void(*)(T &)  func,
T &  param 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 211 of file threads.h.

References mrpt::system::detail::ThreadCreateFunctor< T >::createThread().

◆ exitThread()

void BASE_IMPEXP mrpt::system::exitThread ( )

Explicit close of the current (running) thread.

Do not use normally, it's better just to return from the running thread function.

See also
createThread

◆ getCurrentThreadHandle()

TThreadHandle BASE_IMPEXP mrpt::system::getCurrentThreadHandle ( )

Returns a handle to the current thread.

◆ getCurrentThreadId()

unsigned long BASE_IMPEXP mrpt::system::getCurrentThreadId ( )

Returns the ID of the current thread.

See also
getCurrentThreadHandle

◆ getCurrentThreadTimes()

void BASE_IMPEXP mrpt::system::getCurrentThreadTimes ( time_t &  creationTime,
time_t &  exitTime,
double &  cpuTime 
)

Returns the creation and exit times of the current thread and its CPU time consumed.

Parameters
creationTimeThe creation time of the thread.
exitTimeThe exit time of the thread, or undefined if it is still running.
cpuTimeThe CPU time consumed by the thread, in seconds.
Exceptions
std::exceptionIf the operation fails
See also
getCurrentThreadHandle, getCurrentThreadId, createThread

◆ getNumberOfProcessors()

unsigned int BASE_IMPEXP mrpt::system::getNumberOfProcessors ( )

Return the number of processors ("cores"), or 1 if it cannot be determined.

◆ joinThread()

void BASE_IMPEXP mrpt::system::joinThread ( const TThreadHandle threadHandle)

Waits until the given thread ends.

See also
createThread

◆ launchProcess()

bool BASE_IMPEXP mrpt::system::launchProcess ( const std::string &  command)

Executes the given command (which may contain a program + arguments), and waits until it finishes.

Returns
false on any error, true otherwise

◆ sleep()

void BASE_IMPEXP mrpt::system::sleep ( int  time_ms)

An OS-independent method for sending the current thread to "sleep" for a given period of time.

Parameters
time_msThe sleep period, in miliseconds.

◆ terminateThread()

void BASE_IMPEXP mrpt::system::terminateThread ( TThreadHandle threadHandle)

Terminate a thread, giving it no choice to delete objects, etc (use only as a last resource)




Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo