Main MRPT website > C++ reference
MRPT logo
Classes | Namespaces | Enumerations | Functions
Threads
[mrpt-base]
Collaboration diagram for Threads:

Classes

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

Namespaces

namespace  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.
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.
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.
unsigned long BASE_IMPEXP mrpt::system::getCurrentThreadId () MRPT_NO_THROWS
 Returns the ID of the current thread.
TThreadHandle BASE_IMPEXP mrpt::system::getCurrentThreadHandle () MRPT_NO_THROWS
 Returns a handle to the current thread.
void BASE_IMPEXP mrpt::system::exitThread () MRPT_NO_THROWS
 Explicit close of the current (running) thread.
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.
void BASE_IMPEXP mrpt::system::changeThreadPriority (const TThreadHandle &threadHandle, TThreadPriority priority)
 Change the priority of the given thread.
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)
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).
unsigned int BASE_IMPEXP mrpt::system::getNumberOfProcessors ()
 Return the number of processors ("cores"), or 1 if it cannot be determined.
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.
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.

Enumeration Type Documentation

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

See also:
changeCurrentProcessPriority
Enumerator:
ppIdle 
ppNormal 
ppHigh 
ppVeryHigh 

Definition at line 89 of file threads.h.

The type for cross-platform thread priorities.

See also:
changeThreadPriority
Enumerator:
tpLowests 
tpLower 
tpLow 
tpNormal 
tpHigh 
tpHigher 
tpHighest 

Definition at line 99 of file threads.h.


Function Documentation

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
void BASE_IMPEXP mrpt::system::changeThreadPriority ( const TThreadHandle &  threadHandle,
TThreadPriority  priority 
)

Change the priority of the given thread.

See also:
createThread, changeCurrentProcessPriority
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 200 of file threads.h.

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

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 208 of file threads.h.

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

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 235 of file threads.h.

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

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 245 of file threads.h.

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

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 240 of file threads.h.

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

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 204 of file threads.h.

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

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
TThreadHandle BASE_IMPEXP mrpt::system::getCurrentThreadHandle ( )

Returns a handle to the current thread.

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

Returns the ID of the current thread.

See also:
getCurrentThreadHandle
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
unsigned int BASE_IMPEXP mrpt::system::getNumberOfProcessors ( )

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

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

Waits until the given thread ends.

See also:
createThread
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
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.
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.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011