<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>threads.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> > <b>C++ reference</b> </div> <div align="right"> <a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a> </div> <!-- Generated by Doxygen 1.7.5 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li> <div id="MSearchBox" class="MSearchBoxInactive"> <div class="left"> <form id="FSearchBox" action="search.php" method="get"> <img id="MSearchSelect" src="search/mag.png" alt=""/> <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)"/> </form> </div><div class="right"></div> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">threads.h</div> </div> </div> <div class="contents"> <a href="threads_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* +---------------------------------------------------------------------------+</span> <a name="l00002"></a>00002 <span class="comment"> | The Mobile Robot Programming Toolkit (MRPT) C++ library |</span> <a name="l00003"></a>00003 <span class="comment"> | |</span> <a name="l00004"></a>00004 <span class="comment"> | http://www.mrpt.org/ |</span> <a name="l00005"></a>00005 <span class="comment"> | |</span> <a name="l00006"></a>00006 <span class="comment"> | Copyright (C) 2005-2011 University of Malaga |</span> <a name="l00007"></a>00007 <span class="comment"> | |</span> <a name="l00008"></a>00008 <span class="comment"> | This software was written by the Machine Perception and Intelligent |</span> <a name="l00009"></a>00009 <span class="comment"> | Robotics Lab, University of Malaga (Spain). |</span> <a name="l00010"></a>00010 <span class="comment"> | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |</span> <a name="l00011"></a>00011 <span class="comment"> | |</span> <a name="l00012"></a>00012 <span class="comment"> | This file is part of the MRPT project. |</span> <a name="l00013"></a>00013 <span class="comment"> | |</span> <a name="l00014"></a>00014 <span class="comment"> | MRPT is free software: you can redistribute it and/or modify |</span> <a name="l00015"></a>00015 <span class="comment"> | it under the terms of the GNU General Public License as published by |</span> <a name="l00016"></a>00016 <span class="comment"> | the Free Software Foundation, either version 3 of the License, or |</span> <a name="l00017"></a>00017 <span class="comment"> | (at your option) any later version. |</span> <a name="l00018"></a>00018 <span class="comment"> | |</span> <a name="l00019"></a>00019 <span class="comment"> | MRPT is distributed in the hope that it will be useful, |</span> <a name="l00020"></a>00020 <span class="comment"> | but WITHOUT ANY WARRANTY; without even the implied warranty of |</span> <a name="l00021"></a>00021 <span class="comment"> | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |</span> <a name="l00022"></a>00022 <span class="comment"> | GNU General Public License for more details. |</span> <a name="l00023"></a>00023 <span class="comment"> | |</span> <a name="l00024"></a>00024 <span class="comment"> | You should have received a copy of the GNU General Public License |</span> <a name="l00025"></a>00025 <span class="comment"> | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |</span> <a name="l00026"></a>00026 <span class="comment"> | |</span> <a name="l00027"></a>00027 <span class="comment"> +---------------------------------------------------------------------------+ */</span> <a name="l00028"></a>00028 <span class="preprocessor">#ifndef MRPT_SYSTEM_THREADS_H</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define MRPT_SYSTEM_THREADS_H</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <<a class="code" href="utils__defs_8h.html">mrpt/utils/utils_defs.h</a>></span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="keyword">namespace </span>mrpt <a name="l00034"></a>00034 { <a name="l00035"></a>00035 <span class="keyword">namespace </span>system <a name="l00036"></a>00036 {<span class="comment"></span> <a name="l00037"></a>00037 <span class="comment"> /** \addtogroup mrpt_thread Threads</span> <a name="l00038"></a>00038 <span class="comment"> * \ingroup mrpt_base_grp</span> <a name="l00039"></a>00039 <span class="comment"> * @{ */</span> <a name="l00040"></a>00040 <span class="comment"></span> <a name="l00041"></a>00041 <span class="comment"> /** This structure contains the information needed to interface the threads API on each platform:</span> <a name="l00042"></a>00042 <span class="comment"> * \sa createThread</span> <a name="l00043"></a>00043 <span class="comment"> */</span> <a name="l00044"></a>00044 <span class="keyword">struct </span>TThreadHandle <a name="l00045"></a>00045 { <a name="l00046"></a>00046 <span class="preprocessor">#ifdef MRPT_OS_WINDOWS</span> <a name="l00047"></a>00047 <span class="preprocessor"></span> TThreadHandle() : <span class="comment">//!< Sets the handle to a predefined value meaning it is uninitialized.</span> <a name="l00048"></a>00048 <span class="comment"></span> hThread(NULL), <a name="l00049"></a>00049 idThread(0) <a name="l00050"></a>00050 { <a name="l00051"></a>00051 } <a name="l00052"></a>00052 <span class="comment"></span> <a name="l00053"></a>00053 <span class="comment"> /** Mark the handle as invalid.</span> <a name="l00054"></a>00054 <span class="comment"> * \sa isClear</span> <a name="l00055"></a>00055 <span class="comment"> */</span> <a name="l00056"></a>00056 <span class="keywordtype">void</span> clear() <a name="l00057"></a>00057 { <a name="l00058"></a>00058 idThread = 0; <a name="l00059"></a>00059 hThread = NULL; <a name="l00060"></a>00060 } <a name="l00061"></a>00061 <span class="keywordtype">void</span> *hThread; <span class="comment">//!< The thread "HANDLE"</span> <a name="l00062"></a>00062 <span class="comment"></span><span class="preprocessor"># if defined(HAVE_OPENTHREAD) // defined(_MSC_VER) && (_MSC_VER>=1400)</span> <a name="l00063"></a>00063 <span class="preprocessor"></span> uintptr_t idThread; <span class="comment">//!< The thread ID.</span> <a name="l00064"></a>00064 <span class="comment"></span><span class="preprocessor"># else</span> <a name="l00065"></a>00065 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> idThread; <span class="comment">//!< The thread ID.</span> <a name="l00066"></a>00066 <span class="comment"></span><span class="preprocessor"># endif</span> <a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#if defined(MRPT_OS_LINUX) || defined(MRPT_OS_APPLE)</span> <a name="l00069"></a>00069 <span class="preprocessor"></span> TThreadHandle() : idThread(0) <span class="comment">//!< Sets the handle to a predefined value meaning it is uninitialized.</span> <a name="l00070"></a>00070 <span class="comment"></span> { <a name="l00071"></a>00071 } <a name="l00072"></a>00072 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> idThread; <span class="comment">//!< The thread ID.</span> <a name="l00073"></a>00073 <span class="comment"></span><span class="comment"></span> <a name="l00074"></a>00074 <span class="comment"> /** Mark the handle as invalid.</span> <a name="l00075"></a>00075 <span class="comment"> * \sa isClear</span> <a name="l00076"></a>00076 <span class="comment"> */</span> <a name="l00077"></a>00077 <span class="keywordtype">void</span> clear() <a name="l00078"></a>00078 { <a name="l00079"></a>00079 idThread = 0; <a name="l00080"></a>00080 } <a name="l00081"></a>00081 <span class="preprocessor">#endif</span> <a name="l00082"></a>00082 <span class="preprocessor"></span><span class="comment"> /** Returns true if the handle is uninitialized */</span> <a name="l00083"></a><a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html#a6ae886c8294dd19cba4583c235c72e05">00083</a> <span class="keywordtype">bool</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html#a6ae886c8294dd19cba4583c235c72e05" title="Returns true if the handle is uninitialized.">isClear</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> idThread==0; } <a name="l00084"></a>00084 }; <a name="l00085"></a>00085 <span class="comment"></span> <a name="l00086"></a>00086 <span class="comment"> /** The type for cross-platform process (application) priorities.</span> <a name="l00087"></a>00087 <span class="comment"> * \sa changeCurrentProcessPriority</span> <a name="l00088"></a>00088 <span class="comment"> */</span> <a name="l00089"></a><a class="code" href="group__mrpt__thread.html#ga8c2faa8d1ee370745e9f2c89a417bfa7">00089</a> <span class="keyword">enum</span> <a class="code" href="group__mrpt__thread.html#ga8c2faa8d1ee370745e9f2c89a417bfa7" title="The type for cross-platform process (application) priorities.">TProcessPriority</a> { <a name="l00090"></a><a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7a11576a4e0680e8495b63a94fa985abfc">00090</a> <a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7a11576a4e0680e8495b63a94fa985abfc">ppIdle</a> = 0, <a name="l00091"></a><a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7ad46800cfc911ac0aeb26f404f1a9e878">00091</a> <a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7ad46800cfc911ac0aeb26f404f1a9e878">ppNormal</a>, <a name="l00092"></a><a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7a192fc163166ceb14848bd98f1bd85fb4">00092</a> <a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7a192fc163166ceb14848bd98f1bd85fb4">ppHigh</a>, <a name="l00093"></a><a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7a14f9bd2a1ce9ee2f9a12efba60b29fbb">00093</a> <a class="code" href="group__mrpt__thread.html#gga8c2faa8d1ee370745e9f2c89a417bfa7a14f9bd2a1ce9ee2f9a12efba60b29fbb">ppVeryHigh</a> <a name="l00094"></a>00094 }; <a name="l00095"></a>00095 <span class="comment"></span> <a name="l00096"></a>00096 <span class="comment"> /** The type for cross-platform thread priorities.</span> <a name="l00097"></a>00097 <span class="comment"> * \sa changeThreadPriority</span> <a name="l00098"></a>00098 <span class="comment"> */</span> <a name="l00099"></a><a class="code" href="group__mrpt__thread.html#ga37334359dc65d0cbef086685c837d27f">00099</a> <span class="keyword">enum</span> <a class="code" href="group__mrpt__thread.html#ga37334359dc65d0cbef086685c837d27f" title="The type for cross-platform thread priorities.">TThreadPriority</a> { <a name="l00100"></a><a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27faae6a0fd19982e5399847a60d84c6a331">00100</a> <a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27faae6a0fd19982e5399847a60d84c6a331">tpLowests</a> =-15, <span class="comment">// Win32: THREAD_PRIORITY_IDLE</span> <a name="l00101"></a><a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa3db6aa1cdd443d3e9a3720ab3359ad3c">00101</a> <a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa3db6aa1cdd443d3e9a3720ab3359ad3c">tpLower</a> = -2, <span class="comment">// Win32: THREAD_PRIORITY_LOWEST</span> <a name="l00102"></a><a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa9948aeb6966e10119b2d071b03e1413f">00102</a> <a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa9948aeb6966e10119b2d071b03e1413f">tpLow</a> = -1, <span class="comment">// Win32: THREAD_PRIORITY_BELOW_NORMAL</span> <a name="l00103"></a><a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa243a1b412b7e45a03e20a29929f8623e">00103</a> <a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa243a1b412b7e45a03e20a29929f8623e">tpNormal</a> = 0, <span class="comment">// Win32: THREAD_PRIORITY_NORMAL</span> <a name="l00104"></a><a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa38bb74f11a1213377c6ee7f353df5db9">00104</a> <a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa38bb74f11a1213377c6ee7f353df5db9">tpHigh</a> = 1, <span class="comment">// Win32: THREAD_PRIORITY_ABOVE_NORMAL</span> <a name="l00105"></a><a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fadc1841e96aacf7d7facd67c800db8fea">00105</a> <a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fadc1841e96aacf7d7facd67c800db8fea">tpHigher</a> = 2, <span class="comment">// Win32: THREAD_PRIORITY_HIGHEST</span> <a name="l00106"></a><a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa728be646684f5ed4faf4ec507e3c9bcd">00106</a> <a class="code" href="group__mrpt__thread.html#gga37334359dc65d0cbef086685c837d27fa728be646684f5ed4faf4ec507e3c9bcd">tpHighest</a> = 15 <span class="comment">// Win32: THREAD_PRIORITY_TIME_CRITICAL</span> <a name="l00107"></a>00107 }; <a name="l00108"></a>00108 <span class="comment"></span> <a name="l00109"></a>00109 <span class="comment"> /** Auxiliary classes used internally to MRPT */</span> <a name="l00110"></a><a class="code" href="namespacemrpt_1_1system_1_1detail.html">00110</a> <span class="keyword">namespace </span>detail { <a name="l00111"></a>00111 <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="namespacemrpt_1_1system_1_1detail.html#a949845a7edb999487370797e93e2a528">createThreadImpl</a>(<span class="keywordtype">void</span> (*func)(<span class="keywordtype">void</span> *),<span class="keywordtype">void</span> *param); <a name="l00112"></a>00112 <span class="keyword">template</span><<span class="keyword">typename</span> T> <span class="keyword">class </span><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html">ThreadCreateFunctor</a> { <span class="comment">//T may (and should!) be passed by reference, but mustn't be const.</span> <a name="l00113"></a>00113 <span class="keyword">public</span>: <a name="l00114"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a463852a383aca690d1af623873e8c8eb">00114</a> void (*<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a463852a383aca690d1af623873e8c8eb">func</a>)(T); <a name="l00115"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a1ac9093b000d1a8638dafd24f0b8ceaf">00115</a> T <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a1ac9093b000d1a8638dafd24f0b8ceaf">obj</a>; <a name="l00116"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a3a5d9ca47bd125d8ac07029b4007c6ae">00116</a> <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a3a5d9ca47bd125d8ac07029b4007c6ae">ThreadCreateFunctor</a>(<span class="keywordtype">void</span> (*f)(T),T o):<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a463852a383aca690d1af623873e8c8eb">func</a>(f),<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a1ac9093b000d1a8638dafd24f0b8ceaf">obj</a>(o) {} <a name="l00117"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#afb267291fc9dfb51627b04035f89505e">00117</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#afb267291fc9dfb51627b04035f89505e">createThreadAux</a>(<span class="keywordtype">void</span> *<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a1ac9093b000d1a8638dafd24f0b8ceaf">obj</a>) { <a name="l00118"></a>00118 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html">ThreadCreateFunctor<T></a> *auxStruct=<span class="keyword">static_cast<</span><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html">ThreadCreateFunctor<T></a> *<span class="keyword">></span>(<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a1ac9093b000d1a8638dafd24f0b8ceaf">obj</a>); <a name="l00119"></a>00119 auxStruct-><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a463852a383aca690d1af623873e8c8eb">func</a>(auxStruct-><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a1ac9093b000d1a8638dafd24f0b8ceaf">obj</a>); <a name="l00120"></a>00120 <span class="keyword">delete</span> auxStruct; <a name="l00121"></a>00121 } <a name="l00122"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a5dad1fab2ab2fb2104f3dadeb1183057">00122</a> <span class="keyword">inline</span> <span class="keyword">static</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a5dad1fab2ab2fb2104f3dadeb1183057">createThread</a>(<span class="keywordtype">void</span> (*f)(T),T param) { <a name="l00123"></a>00123 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html">ThreadCreateFunctor</a> *tcs=<span class="keyword">new</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a3a5d9ca47bd125d8ac07029b4007c6ae">ThreadCreateFunctor</a>(f,param); <a name="l00124"></a>00124 <span class="keywordflow">return</span> <a class="code" href="namespacemrpt_1_1system_1_1detail.html#a949845a7edb999487370797e93e2a528">createThreadImpl</a>(&<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#afb267291fc9dfb51627b04035f89505e">createThreadAux</a>,static_cast<void *>(tcs)); <a name="l00125"></a>00125 } <a name="l00126"></a>00126 }; <a name="l00127"></a>00127 <span class="comment">// Specialization for T=void*, which is easier to handle:</span> <a name="l00128"></a>00128 <span class="keyword">template</span><> <span class="keyword">class </span>ThreadCreateFunctor<void *> { <a name="l00129"></a>00129 <span class="keyword">public</span>: <a name="l00130"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_3_01void_01_5_01_4.html#a8f922a0a9b3269920d488ea6167c3edc">00130</a> <span class="keyword">inline</span> <span class="keyword">static</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_3_01void_01_5_01_4.html#a8f922a0a9b3269920d488ea6167c3edc">createThread</a>(<span class="keywordtype">void</span> (*f)(<span class="keywordtype">void</span> *),<span class="keywordtype">void</span> *param) { <a name="l00131"></a>00131 <span class="keywordflow">return</span> <a class="code" href="namespacemrpt_1_1system_1_1detail.html#a949845a7edb999487370797e93e2a528">createThreadImpl</a>(f,param); <a name="l00132"></a>00132 } <a name="l00133"></a>00133 }; <a name="l00134"></a>00134 <span class="comment">// Special case, since T cannot be "void":</span> <a name="l00135"></a>00135 <span class="keyword">class </span>ThreadCreateFunctorNoParams { <a name="l00136"></a>00136 <span class="keyword">public</span>: <a name="l00137"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#a1c25a8c63e2d2cbd71225abb178593d9">00137</a> void (*<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#a1c25a8c63e2d2cbd71225abb178593d9">func</a>)(void); <a name="l00138"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#ae46c00f3d85d92ef68abaabc80348b4d">00138</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#ae46c00f3d85d92ef68abaabc80348b4d">ThreadCreateFunctorNoParams</a>( <span class="keywordtype">void</span> (*f)(<span class="keywordtype">void</span>) ) : <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#a1c25a8c63e2d2cbd71225abb178593d9">func</a>(f) { } <a name="l00139"></a>00139 <a name="l00140"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#aa45d3af87a6aa648be578f132024e243">00140</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#aa45d3af87a6aa648be578f132024e243">createThreadAux</a>(<span class="keywordtype">void</span> *f) { <a name="l00141"></a>00141 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html">ThreadCreateFunctorNoParams</a> *d=<span class="keyword">static_cast<</span><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html">ThreadCreateFunctorNoParams</a>*<span class="keyword">></span>(f); <a name="l00142"></a>00142 d->func(); <span class="comment">// Call the user function.</span> <a name="l00143"></a>00143 <span class="keyword">delete</span> d; <a name="l00144"></a>00144 } <a name="l00145"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#a49d6c8e612ca581061b189d89d15d5c5">00145</a> <span class="keyword">inline</span> <span class="keyword">static</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#a49d6c8e612ca581061b189d89d15d5c5">createThread</a>( <span class="keywordtype">void</span> (*f)(<span class="keywordtype">void</span>) ) { <a name="l00146"></a>00146 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html">ThreadCreateFunctorNoParams</a> *dat = <span class="keyword">new</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#ae46c00f3d85d92ef68abaabc80348b4d">ThreadCreateFunctorNoParams</a>(f); <a name="l00147"></a>00147 <span class="keywordflow">return</span> <a class="code" href="namespacemrpt_1_1system_1_1detail.html#a949845a7edb999487370797e93e2a528">createThreadImpl</a>(&<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#aa45d3af87a6aa648be578f132024e243">createThreadAux</a>, static_cast<void*>(dat) ); <a name="l00148"></a>00148 } <a name="l00149"></a>00149 }; <a name="l00150"></a>00150 <span class="comment">// Template for running a non-static method of an object as a thread.</span> <a name="l00151"></a>00151 <span class="keyword">template</span> <<span class="keyword">class</span> CLASS,<span class="keyword">class</span> PARAM> <a name="l00152"></a>00152 <span class="keyword">class </span>ThreadCreateObjectFunctor { <a name="l00153"></a>00153 <span class="keyword">public</span>: <a name="l00154"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ae2598138d741f6c3906c625eb1e4540e">00154</a> <span class="keyword">typedef</span> void (CLASS::*<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ae2598138d741f6c3906c625eb1e4540e">objectfunctor_t</a>)(PARAM); <a name="l00155"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#aab7054174db3cd6923223f82342659ae">00155</a> CLASS *<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#aab7054174db3cd6923223f82342659ae">obj</a>; <a name="l00156"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#aa45d550c0645157ca1f00fc414adedbe">00156</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ae2598138d741f6c3906c625eb1e4540e">objectfunctor_t</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#aa45d550c0645157ca1f00fc414adedbe">func</a>; <a name="l00157"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#abd024b4a36a7d15b84e21176764a4ae2">00157</a> PARAM <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#abd024b4a36a7d15b84e21176764a4ae2">p</a>; <a name="l00158"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#a4a504c7a73dfd40f8c11aaafe1398c55">00158</a> <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#a4a504c7a73dfd40f8c11aaafe1398c55">ThreadCreateObjectFunctor</a>(CLASS *o,<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ae2598138d741f6c3906c625eb1e4540e">objectfunctor_t</a> f, PARAM param):<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#aab7054174db3cd6923223f82342659ae">obj</a>(o),<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#aa45d550c0645157ca1f00fc414adedbe">func</a>(f),<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#abd024b4a36a7d15b84e21176764a4ae2">p</a>(param) {} <a name="l00159"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ac9e0749da465654a4d93f744d00ed66f">00159</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ac9e0749da465654a4d93f744d00ed66f">createThreadAux</a>(<span class="keywordtype">void</span> *<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#abd024b4a36a7d15b84e21176764a4ae2">p</a>) { <a name="l00160"></a>00160 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html">ThreadCreateObjectFunctor<CLASS,PARAM></a> *auxStruct=<span class="keyword">static_cast<</span><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html">ThreadCreateObjectFunctor<CLASS,PARAM></a>*<span class="keyword">></span>(<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#abd024b4a36a7d15b84e21176764a4ae2">p</a>); <a name="l00161"></a>00161 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ae2598138d741f6c3906c625eb1e4540e">objectfunctor_t</a> f = auxStruct->func; <a name="l00162"></a>00162 (auxStruct->obj->*f)(auxStruct->p); <a name="l00163"></a>00163 <span class="keyword">delete</span> auxStruct; <a name="l00164"></a>00164 } <a name="l00165"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#a175f2fec6110b428464ecba601036ce0">00165</a> <span class="keyword">inline</span> <span class="keyword">static</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#a175f2fec6110b428464ecba601036ce0">createThread</a>(CLASS *o,<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ae2598138d741f6c3906c625eb1e4540e">objectfunctor_t</a> f, PARAM param) { <a name="l00166"></a>00166 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html">ThreadCreateObjectFunctor</a> *tcs=<span class="keyword">new</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#a4a504c7a73dfd40f8c11aaafe1398c55">ThreadCreateObjectFunctor</a>(o,f,param); <a name="l00167"></a>00167 <span class="keywordflow">return</span> <a class="code" href="namespacemrpt_1_1system_1_1detail.html#a949845a7edb999487370797e93e2a528">createThreadImpl</a>(&<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#ac9e0749da465654a4d93f744d00ed66f">createThreadAux</a>,static_cast<void *>(tcs)); <a name="l00168"></a>00168 } <a name="l00169"></a>00169 }; <a name="l00170"></a>00170 <span class="comment">// Template for running a non-static method of an object as a thread - no params</span> <a name="l00171"></a>00171 <span class="keyword">template</span> <<span class="keyword">class</span> CLASS> <a name="l00172"></a>00172 <span class="keyword">class </span>ThreadCreateObjectFunctorNoParams { <a name="l00173"></a>00173 <span class="keyword">public</span>: <a name="l00174"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a75558bfa1e3f79e725cc29623b057cb0">00174</a> <span class="keyword">typedef</span> void (CLASS::*<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a75558bfa1e3f79e725cc29623b057cb0">objectfunctor_t</a>)(void); <a name="l00175"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a72dd61f19303a5ce344b547238d1da53">00175</a> CLASS *<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a72dd61f19303a5ce344b547238d1da53">obj</a>; <a name="l00176"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#afd86a065aa5ee4df2a7d03c78d23b699">00176</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a75558bfa1e3f79e725cc29623b057cb0">objectfunctor_t</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#afd86a065aa5ee4df2a7d03c78d23b699">func</a>; <a name="l00177"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#afb7982d62d707c0d3e4fc9c93a610db7">00177</a> <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#afb7982d62d707c0d3e4fc9c93a610db7">ThreadCreateObjectFunctorNoParams</a>(CLASS *o,<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a75558bfa1e3f79e725cc29623b057cb0">objectfunctor_t</a> f):<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a72dd61f19303a5ce344b547238d1da53">obj</a>(o),<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#afd86a065aa5ee4df2a7d03c78d23b699">func</a>(f) {} <a name="l00178"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a8a0241ea18b28da68affb45fb6cb51ce">00178</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a8a0241ea18b28da68affb45fb6cb51ce">createThreadAux</a>(<span class="keywordtype">void</span> *p) { <a name="l00179"></a>00179 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html">ThreadCreateObjectFunctorNoParams<CLASS></a> *auxStruct=<span class="keyword">static_cast<</span><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html">ThreadCreateObjectFunctorNoParams<CLASS></a>*<span class="keyword">></span>(p); <a name="l00180"></a>00180 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a75558bfa1e3f79e725cc29623b057cb0">objectfunctor_t</a> f = auxStruct->func; <a name="l00181"></a>00181 (auxStruct->obj->*f)(); <a name="l00182"></a>00182 <span class="keyword">delete</span> auxStruct; <a name="l00183"></a>00183 } <a name="l00184"></a><a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a19802d6251c833ddfac49b0b417f5ea6">00184</a> <span class="keyword">inline</span> <span class="keyword">static</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a19802d6251c833ddfac49b0b417f5ea6">createThread</a>(CLASS *o,<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a75558bfa1e3f79e725cc29623b057cb0">objectfunctor_t</a> f) { <a name="l00185"></a>00185 <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html">ThreadCreateObjectFunctorNoParams</a> *tcs=<span class="keyword">new</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#afb7982d62d707c0d3e4fc9c93a610db7">ThreadCreateObjectFunctorNoParams</a>(o,f); <a name="l00186"></a>00186 <span class="keywordflow">return</span> <a class="code" href="namespacemrpt_1_1system_1_1detail.html#a949845a7edb999487370797e93e2a528">createThreadImpl</a>(&<a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a8a0241ea18b28da68affb45fb6cb51ce">createThreadAux</a>,static_cast<void *>(tcs)); <a name="l00187"></a>00187 } <a name="l00188"></a>00188 }; <a name="l00189"></a>00189 } <span class="comment">// end detail</span> <a name="l00190"></a>00190 <span class="comment"></span> <a name="l00191"></a>00191 <span class="comment"> /** Creates a new thread from a function (or static method) with one generic parameter.</span> <a name="l00192"></a>00192 <span class="comment"> * This function creates, and start, a new thread running some code given by a function.</span> <a name="l00193"></a>00193 <span class="comment"> * The thread function should end by returning as normal.</span> <a name="l00194"></a>00194 <span class="comment"> * \param func The function with the code to run in the thread.</span> <a name="l00195"></a>00195 <span class="comment"> * \param param The parameter to be passed to the new thread function.</span> <a name="l00196"></a>00196 <span class="comment"> * \return A structure that represents the thread (it contains its ID and, in Windows, its HANDLE).</span> <a name="l00197"></a>00197 <span class="comment"> * \exception std::exception If the operation fails</span> <a name="l00198"></a>00198 <span class="comment"> * \sa createThreadFromObjectMethod, joinThread, changeThreadPriority</span> <a name="l00199"></a>00199 <span class="comment"> */</span> <a name="l00200"></a><a class="code" href="group__mrpt__thread.html#ga336f5607e34b84bc7ac208068aa8e51e">00200</a> <span class="keyword">template</span><<span class="keyword">typename</span> T> <span class="keyword">inline</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="group__mrpt__thread.html#ga336f5607e34b84bc7ac208068aa8e51e" title="Creates a new thread from a function (or static method) with one generic parameter.">createThread</a>(<span class="keywordtype">void</span> (*func)(T),T param) { <a name="l00201"></a>00201 <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a5dad1fab2ab2fb2104f3dadeb1183057">detail::ThreadCreateFunctor<T>::createThread</a>(func,param); <a name="l00202"></a>00202 }<span class="comment"></span> <a name="l00203"></a>00203 <span class="comment"> //! \overload</span> <a name="l00204"></a><a class="code" href="group__mrpt__thread.html#ga81d1604616b261ab0b5536bcf6657f03">00204</a> <span class="comment"></span> <span class="keyword">template</span><<span class="keyword">typename</span> T> <span class="keyword">inline</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="group__mrpt__thread.html#ga81d1604616b261ab0b5536bcf6657f03">createThreadRef</a>(<span class="keywordtype">void</span> (*func)(T&),T& param) { <a name="l00205"></a>00205 <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor.html#a5dad1fab2ab2fb2104f3dadeb1183057">detail::ThreadCreateFunctor<T&>::createThread</a>(func,param); <a name="l00206"></a>00206 }<span class="comment"></span> <a name="l00207"></a>00207 <span class="comment"> //! \overload</span> <a name="l00208"></a><a class="code" href="group__mrpt__thread.html#gac7a010553c47446af4b7ab7b1abf5a74">00208</a> <span class="comment"></span> <span class="keyword">inline</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="group__mrpt__thread.html#ga336f5607e34b84bc7ac208068aa8e51e" title="Creates a new thread from a function (or static method) with one generic parameter.">createThread</a>(<span class="keywordtype">void</span> (*func)(<span class="keywordtype">void</span>)) { <a name="l00209"></a>00209 <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_functor_no_params.html#a49d6c8e612ca581061b189d89d15d5c5">detail::ThreadCreateFunctorNoParams::createThread</a>(func); <a name="l00210"></a>00210 } <a name="l00211"></a>00211 <span class="comment"></span> <a name="l00212"></a>00212 <span class="comment"> /** 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.</span> <a name="l00213"></a>00213 <span class="comment"> * This function creates, and start, a new thread running some code given by a function.</span> <a name="l00214"></a>00214 <span class="comment"> * The thread function should end by returning as normal.</span> <a name="l00215"></a>00215 <span class="comment"> * Example of usage:</span> <a name="l00216"></a>00216 <span class="comment"> *</span> <a name="l00217"></a>00217 <span class="comment"> * \code</span> <a name="l00218"></a>00218 <span class="comment"> * class MyClass {</span> <a name="l00219"></a>00219 <span class="comment"> * public:</span> <a name="l00220"></a>00220 <span class="comment"> * void myThread(int n);</span> <a name="l00221"></a>00221 <span class="comment"> * void someMethod() {</span> <a name="l00222"></a>00222 <span class="comment"> * createThreadFromObjectMethod(this, &MyClass::myThread, 123 );</span> <a name="l00223"></a>00223 <span class="comment"> * ....</span> <a name="l00224"></a>00224 <span class="comment"> * }</span> <a name="l00225"></a>00225 <span class="comment"> * };</span> <a name="l00226"></a>00226 <span class="comment"> * \endcode</span> <a name="l00227"></a>00227 <span class="comment"> *</span> <a name="l00228"></a>00228 <span class="comment"> * \param func The function with the code to run in the thread.</span> <a name="l00229"></a>00229 <span class="comment"> * \param param The parameter to be passed to the new thread function.</span> <a name="l00230"></a>00230 <span class="comment"> * \return A structure that represents the thread (it contains its ID and, in Windows, its HANDLE).</span> <a name="l00231"></a>00231 <span class="comment"> * \exception std::exception If the operation fails</span> <a name="l00232"></a>00232 <span class="comment"> * \sa createThread, joinThread, changeThreadPriority</span> <a name="l00233"></a>00233 <span class="comment"> */</span> <a name="l00234"></a>00234 <span class="keyword">template</span> <<span class="keyword">typename</span> CLASS,<span class="keyword">typename</span> PARAM> <a name="l00235"></a><a class="code" href="group__mrpt__thread.html#ga04ca9cd3d32cc923c6fd4e42fc196e85">00235</a> <span class="keyword">inline</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="group__mrpt__thread.html#ga04ca9cd3d32cc923c6fd4e42fc196e85" title="Creates a new thread running a non-static method (so it will have access to "this") from another meth...">createThreadFromObjectMethod</a>(CLASS *obj, <span class="keywordtype">void</span> (CLASS::*func)(PARAM), PARAM param) { <a name="l00236"></a>00236 <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#a175f2fec6110b428464ecba601036ce0">detail::ThreadCreateObjectFunctor<CLASS,PARAM>::createThread</a>(obj,func,param); <a name="l00237"></a>00237 }<span class="comment"></span> <a name="l00238"></a>00238 <span class="comment"> //! \overload</span> <a name="l00239"></a>00239 <span class="comment"></span> <span class="keyword">template</span> <<span class="keyword">typename</span> CLASS,<span class="keyword">typename</span> PARAM> <a name="l00240"></a><a class="code" href="group__mrpt__thread.html#ga69b2eb14aae15372652e1600b192f74e">00240</a> <span class="keyword">inline</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="group__mrpt__thread.html#ga69b2eb14aae15372652e1600b192f74e">createThreadFromObjectMethodRef</a>(CLASS *obj, <span class="keywordtype">void</span> (CLASS::*func)(PARAM), PARAM &param) { <a name="l00241"></a>00241 <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor.html#a175f2fec6110b428464ecba601036ce0">detail::ThreadCreateObjectFunctor<CLASS,PARAM&>::createThread</a>(obj,func,param); <a name="l00242"></a>00242 }<span class="comment"></span> <a name="l00243"></a>00243 <span class="comment"> //! \overload</span> <a name="l00244"></a>00244 <span class="comment"></span> <span class="keyword">template</span> <<span class="keyword">typename</span> CLASS> <a name="l00245"></a><a class="code" href="group__mrpt__thread.html#gab663a7d9d2285640bd5f2bbe473568cb">00245</a> <span class="keyword">inline</span> <a class="code" href="structmrpt_1_1system_1_1_t_thread_handle.html" title="This structure contains the information needed to interface the threads API on each platform:...">TThreadHandle</a> <a class="code" href="group__mrpt__thread.html#ga04ca9cd3d32cc923c6fd4e42fc196e85" title="Creates a new thread running a non-static method (so it will have access to "this") from another meth...">createThreadFromObjectMethod</a>(CLASS *obj, <span class="keywordtype">void</span> (CLASS::*func)(<span class="keywordtype">void</span>)) { <a name="l00246"></a>00246 <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1system_1_1detail_1_1_thread_create_object_functor_no_params.html#a19802d6251c833ddfac49b0b417f5ea6">detail::ThreadCreateObjectFunctorNoParams<CLASS>::createThread</a>(obj,func); <a name="l00247"></a>00247 } <a name="l00248"></a>00248 <a name="l00249"></a>00249 <span class="comment"></span> <a name="l00250"></a>00250 <span class="comment"> /** Waits until the given thread ends.</span> <a name="l00251"></a>00251 <span class="comment"> * \sa createThread</span> <a name="l00252"></a>00252 <span class="comment"> */</span> <a name="l00253"></a>00253 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#ga723810cea7feb46c7391c245c5c5eec2" title="Waits until the given thread ends.">joinThread</a>( <span class="keyword">const</span> TThreadHandle &threadHandle ); <a name="l00254"></a>00254 <span class="comment"></span> <a name="l00255"></a>00255 <span class="comment"> /** Returns the ID of the current thread.</span> <a name="l00256"></a>00256 <span class="comment"> * \sa getCurrentThreadHandle</span> <a name="l00257"></a>00257 <span class="comment"> */</span> <a name="l00258"></a>00258 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#ga826a49a3efec4b9e5bc76b3aff870a0a" title="Returns the ID of the current thread.">getCurrentThreadId</a>() <a class="code" href="mrpt__macros_8h.html#afed971bfd24ff010f488cce2aa424de4" title="Used after member declarations.">MRPT_NO_THROWS</a>; <a name="l00259"></a>00259 <span class="comment"></span> <a name="l00260"></a>00260 <span class="comment"> /** Returns a handle to the current thread.</span> <a name="l00261"></a>00261 <span class="comment"> */</span> <a name="l00262"></a>00262 TThreadHandle <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#ga6c18cb71a8a0db7e757015dcab8bde75" title="Returns a handle to the current thread.">getCurrentThreadHandle</a>() <a class="code" href="mrpt__macros_8h.html#afed971bfd24ff010f488cce2aa424de4" title="Used after member declarations.">MRPT_NO_THROWS</a>; <a name="l00263"></a>00263 <span class="comment"></span> <a name="l00264"></a>00264 <span class="comment"> /** Explicit close of the current (running) thread.</span> <a name="l00265"></a>00265 <span class="comment"> * Do not use normally, it's better just to return from the running thread function.</span> <a name="l00266"></a>00266 <span class="comment"> * \sa createThread</span> <a name="l00267"></a>00267 <span class="comment"> */</span> <a name="l00268"></a>00268 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#gabe2474d80e16d3e0a5f755a0cb486658" title="Explicit close of the current (running) thread.">exitThread</a>() MRPT_NO_THROWS; <a name="l00269"></a>00269 <span class="comment"></span> <a name="l00270"></a>00270 <span class="comment"> /** Returns the creation and exit times of the current thread and its CPU time consumed.</span> <a name="l00271"></a>00271 <span class="comment"> * \param creationTime The creation time of the thread.</span> <a name="l00272"></a>00272 <span class="comment"> * \param exitTime The exit time of the thread, or undefined if it is still running.</span> <a name="l00273"></a>00273 <span class="comment"> * \param cpuTime The CPU time consumed by the thread, in seconds.</span> <a name="l00274"></a>00274 <span class="comment"> * \exception std::exception If the operation fails</span> <a name="l00275"></a>00275 <span class="comment"> * \sa getCurrentThreadHandle, getCurrentThreadId, createThread</span> <a name="l00276"></a>00276 <span class="comment"> */</span> <a name="l00277"></a>00277 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#ga07d252d6de608a5cf3a4c1380c2ecdb1" title="Returns the creation and exit times of the current thread and its CPU time consumed.">getCurrentThreadTimes</a>( <a name="l00278"></a>00278 time_t &creationTime, <a name="l00279"></a>00279 time_t &exitTime, <a name="l00280"></a>00280 <span class="keywordtype">double</span> &cpuTime ); <a name="l00281"></a>00281 <span class="comment"></span> <a name="l00282"></a>00282 <span class="comment"> /** Change the priority of the given thread.</span> <a name="l00283"></a>00283 <span class="comment"> * \sa createThread, changeCurrentProcessPriority</span> <a name="l00284"></a>00284 <span class="comment"> */</span> <a name="l00285"></a>00285 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#ga9b12b6fd6d150e35bffd8a8ee8169cd8" title="Change the priority of the given thread.">changeThreadPriority</a>( const TThreadHandle &threadHandle, <a class="code" href="group__mrpt__thread.html#ga37334359dc65d0cbef086685c837d27f" title="The type for cross-platform thread priorities.">TThreadPriority</a> priority ); <a name="l00286"></a>00286 <span class="comment"></span> <a name="l00287"></a>00287 <span class="comment"> /** Terminate a thread, giving it no choice to delete objects, etc (use only as a last resource) */</span> <a name="l00288"></a>00288 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#gafbfb426dee2ea19f7c557b64ef60aa69" title="Terminate a thread, giving it no choice to delete objects, etc (use only as a last resource)...">terminateThread</a>( TThreadHandle &threadHandle) MRPT_NO_THROWS; <a name="l00289"></a>00289 <span class="comment"></span> <a name="l00290"></a>00290 <span class="comment"> /** Change the priority of the given process (it applies to all the threads, plus independent modifiers for each thread).</span> <a name="l00291"></a>00291 <span class="comment"> * \sa createThread, changeThreadPriority</span> <a name="l00292"></a>00292 <span class="comment"> */</span> <a name="l00293"></a>00293 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#gaa4698e4d733682e6ca4277bf6776e8fb" title="Change the priority of the given process (it applies to all the threads, plus independent modifiers f...">changeCurrentProcessPriority</a>( <a class="code" href="group__mrpt__thread.html#ga8c2faa8d1ee370745e9f2c89a417bfa7" title="The type for cross-platform process (application) priorities.">TProcessPriority</a> priority ); <a name="l00294"></a>00294 <span class="comment"></span> <a name="l00295"></a>00295 <span class="comment"> /** Return the number of processors ("cores"), or 1 if it cannot be determined.</span> <a name="l00296"></a>00296 <span class="comment"> */</span> <a name="l00297"></a>00297 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#ga2d962c5a835828188d209dc802623ca5" title="Return the number of processors ("cores"), or 1 if it cannot be determined.">getNumberOfProcessors</a>(); <a name="l00298"></a>00298 <span class="comment"></span> <a name="l00299"></a>00299 <span class="comment"> /** An OS-independent method for sending the current thread to "sleep" for a given period of time.</span> <a name="l00300"></a>00300 <span class="comment"> * \param time_ms The sleep period, in miliseconds.</span> <a name="l00301"></a>00301 <span class="comment"> */</span> <a name="l00302"></a>00302 <span class="keywordtype">void</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#gaade78123d72cf506a2c590ea26ec51ac" title="An OS-independent method for sending the current thread to "sleep" for a given period of time...">sleep</a>( <span class="keywordtype">int</span> time_ms ) MRPT_NO_THROWS; <a name="l00303"></a>00303 <span class="comment"></span> <a name="l00304"></a>00304 <span class="comment"> /** Executes the given command (which may contain a program + arguments), and waits until it finishes.</span> <a name="l00305"></a>00305 <span class="comment"> * \return false on any error, true otherwise</span> <a name="l00306"></a>00306 <span class="comment"> */</span> <a name="l00307"></a>00307 <span class="keywordtype">bool</span> <a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> <a class="code" href="group__mrpt__thread.html#gabc593b2c772be33e679b1a8311a1ca46" title="Executes the given command (which may contain a program + arguments), and waits until it finishes...">launchProcess</a>( const std::<span class="keywordtype">string</span> & command ); <a name="l00308"></a>00308 <span class="comment"></span> <a name="l00309"></a>00309 <span class="comment"> /** @} */</span> <a name="l00310"></a>00310 <a name="l00311"></a>00311 } <span class="comment">// End of namespace</span> <a name="l00312"></a>00312 <a name="l00313"></a>00313 } <span class="comment">// End of namespace</span> <a name="l00314"></a>00314 <a name="l00315"></a>00315 <span class="preprocessor">#endif</span> </pre></div></div> </div> <br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.5</a> for MRPT 0.9.5 SVN: at Sun Sep 25 17:20:18 UTC 2011</td><td></td> <td width="100"> </td> <td width="150"> </td></tr> </table> </body></html>