Main MRPT website > C++ reference for MRPT 1.5.7
Classes | 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
 A MRPT thread handle. More...
 

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 (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...
 
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::changeCurrentThreadPriority (TThreadPriority priority)
 Change the priority of the current thread - for Windows, see also changeCurrentProcessPriority() 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 51 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 61 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).

  • Windows: See SetPriorityClass
  • Linux (pthreads): Requires root permissions to increase process priority! Internally it calls nice(), so it has no effect if () was called and a SCHED_RR is already active.
    See also
    createThread, changeThreadPriority

Definition at line 144 of file threads.cpp.

References mrpt::system::ppHigh, mrpt::system::ppIdle, mrpt::system::ppNormal, mrpt::system::ppVeryHigh, and THROW_EXCEPTION.

◆ changeCurrentThreadPriority()

void BASE_IMPEXP mrpt::system::changeCurrentThreadPriority ( TThreadPriority  priority)

Change the priority of the current thread - for Windows, see also changeCurrentProcessPriority()

Definition at line 94 of file threads.cpp.

References mrpt::system::tpHigh, mrpt::system::tpHigher, mrpt::system::tpHighest, mrpt::system::tpLow, mrpt::system::tpLower, mrpt::system::tpLowests, and mrpt::system::tpNormal.

◆ 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 starts 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 80 of file threads.h.

References mrpt::system::TThreadHandle::m_thread.

Referenced by mrpt::gui::WxSubsystem::createOneInstanceMainThread(), mrpt::detectors::CFaceDetection::init(), mrpt::hwdrivers::CImpinjRFID::initialize(), my_CriticalSections_Multi(), and my_CSemaphore().

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

References mrpt::system::TThreadHandle::m_thread.

◆ 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 starts 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 121 of file threads.h.

References mrpt::system::TThreadHandle::m_thread.

Referenced by mrpt::system::CFileSystemWatcher::CFileSystemWatcher(), mrpt::hmtslam::CHMTSLAM::CHMTSLAM(), mrpt::hwdrivers::CNTRIPClient::CNTRIPClient(), mrpt::hwdrivers::CIbeoLuxETH::initialize(), mrpt::hwdrivers::CCameraSensor::initialize(), mrpt::pbmap::PbMapLocaliser::PbMapLocaliser(), mrpt::pbmap::PbMapMaker::PbMapMaker(), mrpt::hwdrivers::CRovio::retrieve_video(), and mrpt::graphslam::optimizers::CLevMarqGSO< GRAPH_T >::updateState().

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

References mrpt::system::TThreadHandle::m_thread.

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

References mrpt::system::TThreadHandle::m_thread.

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

References mrpt::system::TThreadHandle::m_thread.

Referenced by mrpt::utils::net::DNS_resolve_async().

◆ exitThread()

void 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

Definition at line 367 of file threads.cpp.

Referenced by mrpt::hwdrivers::CImpinjRFID::startDriver().

◆ getCurrentThreadId()

unsigned long mrpt::system::getCurrentThreadId ( )

◆ getCurrentThreadTimes()

void 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
getCurrentThreadId, createThread

Definition at line 180 of file threads.cpp.

References FALSE, mrpt::format(), mrpt::system::getCurrentThreadId(), info, MRPT_END, MRPT_START, MRPT_UNUSED_PARAM, THROW_EXCEPTION, and mrpt::system::tokenize().

Referenced by mrpt::hmtslam::CHMTSLAM::thread_3D_viewer(), mrpt::hmtslam::CHMTSLAM::thread_LSLAM(), and mrpt::hmtslam::CHMTSLAM::thread_TBI().

◆ getNumberOfProcessors()

unsigned int mrpt::system::getNumberOfProcessors ( )

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

Definition at line 327 of file threads.cpp.

◆ joinThread()

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

◆ launchProcess()

bool 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

Definition at line 295 of file threads.cpp.

Referenced by mrpt::vision::CFeatureExtraction::extractFeaturesSIFT(), and mrpt::vision::CFeatureExtraction::internal_computeSiftDescriptors().

◆ sleep()

void 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.

Definition at line 57 of file threads.cpp.

References mrpt::utils::CTicTac::Tac(), and mrpt::utils::CTicTac::Tic().

Referenced by mrpt::slam::CGridMapAligner::AlignPDF_correlation(), mrpt::hwdrivers::CEnoseModular::checkConnectionAndConnect(), mrpt::hwdrivers::CBoardENoses::checkConnectionAndConnect(), mrpt::hwdrivers::CBoardSonars::checkConnectionAndConnect(), mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), mrpt::hwdrivers::CSickLaserUSB::checkControllerIsConnected(), mrpt::hwdrivers::CImpinjRFID::connect(), mrpt::gui::CBaseGUIWindow::createWxWindow(), mrpt::gui::CBaseGUIWindow::destroyWxWindow(), mrpt::detectors::CCascadeClassifierDetection::detectObjects_Impl(), mrpt::hwdrivers::CGillAnemometer::doProcess(), mrpt::hwdrivers::CRaePID::doProcess(), mrpt::hwdrivers::CIMUXSens_MT4::doProcess(), mrpt::hwdrivers::CIMUXSens::doProcess(), mrpt::hwdrivers::CSkeletonTracker::doProcess(), mrpt::hwdrivers::CNTRIPEmitter::doProcess(), mrpt::hwdrivers::CIMUIntersense::doProcess(), mrpt::hwdrivers::CGyroKVHDSP3000::doProcess(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::dumpVisibilityErrorMsg(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::dumpVisibilityErrorMsg(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::dumpVisibilityErrorMsg(), mrpt::hwdrivers::CVelodyneScanner::getNextObservation(), mrpt::hwdrivers::CImageGrabber_OpenCV::getObservation(), mrpt::gui::CBaseGUIWindow::getPushedKey(), mrpt::hwdrivers::CNationalInstrumentsDAQ::grabbing_thread(), mrpt::utils::net::http_request(), mrpt::hwdrivers::CIMUIntersense::initialize(), mrpt::hwdrivers::CVelodyneScanner::internal_read_PCAP_packet(), mrpt::hwdrivers::CGPSInterface::JAVAD_sendMessage(), launchTestWithTimeout(), mrpt::hwdrivers::CGPSInterface::legacy_topcon_setup_commands(), mrpt::hwdrivers::CSickLaserSerial::LMS_setupSerialComms(), xsens::msleep(), my_CriticalSections_Multi(), my_CSemaphore(), mrpt::hwdrivers::CGPSInterface::OnConnectionEstablished(), mrpt::hwdrivers::CGPSInterface::OnConnectionShutdown(), mrpt::hwdrivers::COpenNI2Generic::open(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::pauseExec(), mrpt::hwdrivers::prepareVideoSourceFromUserSelection(), mrpt::hwdrivers::CNTRIPClient::private_ntrip_thread(), mrpt::hwdrivers::CBoardSonars::programI2CAddress(), mrpt::hwdrivers::CServoeNeck::queryFirmwareVersion(), mrpt::hwdrivers::CSerialPort::Read(), mrpt::hwdrivers::CSerialPort::ReadString(), mrpt::hwdrivers::CTuMicos::reset(), mrpt::hwdrivers::CRovio::retrieve_video(), mrpt::pbmap::PbMapLocaliser::run(), mrpt::pbmap::PbMapMaker::run(), mrpt::hwdrivers::CPtuDPerception::scan(), sem_thread_example(), mrpt::hwdrivers::CSickLaserSerial::SendCommandToSICK(), mrpt::hwdrivers::CServoeNeck::setRegisterValue(), mrpt::hwdrivers::CServoeNeck::setRegisterValueAndSpeed(), mrpt::hwdrivers::CCANBusReader::setupSerialComms(), mrpt::hwdrivers::CImpinjRFID::startDriver(), mrpt::hwdrivers::CNationalInstrumentsDAQ::stop(), mrpt::pbmap::PbMapLocaliser::stop_pbMapLocaliser(), mrpt::pbmap::PbMapMaker::stop_pbMapMaker(), mrpt::hmtslam::CHMTSLAM::thread_3D_viewer(), thread_example(), mrpt::hmtslam::CHMTSLAM::thread_LSLAM(), mrpt::hwdrivers::CCameraSensor::thread_save_images(), mrpt::hmtslam::CHMTSLAM::thread_TBI(), mrpt::hwdrivers::CRovio::thread_video(), mrpt::hwdrivers::CLMS100Eth::turnOn(), mrpt::hwdrivers::CGPSInterface::unsetJAVAD_AIM_mode(), mrpt::pbmap::PbMapMaker::viz_cb(), mrpt::hwdrivers::CCANBusReader::waitContinuousSampleFrame(), mrpt::hwdrivers::CSickLaserSerial::waitContinuousSampleFrame(), mrpt::gui::CBaseGUIWindow::waitForKey(), mrpt::gui::WxSubsystem::waitWxShutdownsIfNoWindows(), CGraphSlamHandler< GRAPH_T >::~CGraphSlamHandler(), and mrpt::hwdrivers::CIbeoLuxETH::~CIbeoLuxETH().

◆ terminateThread()

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

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

Definition at line 379 of file threads.cpp.

Referenced by mrpt::system::CFileSystemWatcher::~CFileSystemWatcher().




Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019