<!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>GearBox Project</title> <link rel="icon" href="gbx_icon_cardbox_sky.png" type="image/png"> <link rel="shortcut icon" href="gbx_icon_cardbox_sky.png" type="image/png"> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> <!-- Google Analytics --> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-3583782-1"); pageTracker._initData(); pageTracker._trackPageview(); </script> <!-- Returning you to your regular programming --> </head><body> <!-- Header --> <table border="0" cellspacing="0" cellpadding="0"> <tr><!-- create row --> <!-- spacer cell --> <!-- #CC CC CC --> <td rowspan="1" colspan="1" bgcolor="#EEEEEE"> </td> <!-- menu cell --> <td width="170" rowspan="1" colspan="1" align="left" valign="top" bgcolor="#EEEEEE"> <p> </p> <p align="center"><a href="index.html"><img src="gbx_logo_cardbox_sky_150x150.png"></a></p><br> <strong>INTRODUCTION</strong><br> <strong><a href="gbx_doc_overview.html" style="text-decoration:none">Overview</a></strong><br> <strong><a href="gbx_doc_getting.html" style="text-decoration:none">Download and Install</a></strong><br> <!-- <strong><a href="gbx_doc_quickstart.html" style="text-decoration:none">Quick Start</a></strong><br> --> <strong><a href="gbx_doc_documentation.html" style="text-decoration:none">Documentation</a></strong><br> <strong><a href="gbx_doc_publications.html" style="text-decoration:none">Publications</a></strong><br> <br> <strong>REPOSITORY</strong><br> <strong><a href="group__gbx__libs.html" style="text-decoration:none">Libraries</a></strong><br> <!-- <strong><a href="group__gbx__utils.html" style="text-decoration:none">Utilities</a></strong><br> --> <br> <strong>DEVELOPER</strong><br> <!--<strong><a href="gbx_doc_tutorials.html" style="text-decoration:none">Tutorials</a></strong><br> <strong><a href="group__gbx__examples.html" style="text-decoration:none">Examples</a></strong><br>--> <strong><a href="gbx_doc_devguide.html" style="text-decoration:none">Dev Guide</a></strong><br> <!-- <strong><a href="gbx_doc_faq.html" style="text-decoration:none">FAQ</a></strong><br> --> <strong><a href="http://cdash.acfr.usyd.edu.au/index.php?project=Gearbox" style="text-decoration:none">Dashboard</a></strong><br> <!--<strong><a href="http://wiki2.cas.edu.au/orca">Wiki</a></strong><br> login/pass: orca/orca<br>--> <br> <strong>PEOPLE</strong><br> <strong><a href="gbx_doc_contributors.html" style="text-decoration:none">Contributors</a></strong><br> <strong><a href="gbx_doc_users.html" style="text-decoration:none">Users</a></strong><br> <br> <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=216468&type=2" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a><br> <strong><a href="http://sourceforge.net/projects/gearbox">Project</a></strong><br> <strong><a href="http://sourceforge.net/project/showfiles.php?group_id=216468">Download</a></strong><br> <!--<strong><a href="http://sourceforge.net/tracker/?group_id=216468">Bugs/Feedback</a></strong><br>--> <strong><a href="http://sourceforge.net/mail/?group_id=216468">Mailing lists</a></strong></p> <p> </p> </td><!-- /menu cell --> <!-- one grey spacer cells --> <td rowspan="1" colspan="1" bgcolor="#EEEEEE"> </td> <!-- one white spacer cells --> <td rowspan="1" colspan="1"> </td> <!-- main content cell --> <td rowspan="1" colspan="1" align="left" valign="top"> <!-- Generated by Doxygen 1.6.2-20100208 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <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 class="current"><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="annotated.html"><span>Class List</span></a></li> <li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li> <li><a href="functions.html"><span>Class Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="namespacegbxiceutilacfr.html">gbxiceutilacfr</a>::<a class="el" href="classgbxiceutilacfr_1_1Thread.html">Thread</a> </div> </div> <div class="contents"> <h1>gbxiceutilacfr::Thread Class Reference</h1><!-- doxytag: class="gbxiceutilacfr::Thread" --><!-- doxytag: inherits="gbxutilacfr::Stoppable" --> <p>A minor extention of the IceUtil::Thread class. <a href="#_details">More...</a></p> <p><code>#include <<a class="el" href="thread_8h_source.html">thread.h</a>></code></p> <p>Inherits <a class="el" href="classgbxutilacfr_1_1Stoppable.html">gbxutilacfr::Stoppable</a>.</p> <p>Inherited by <a class="el" href="classgbxiceutilacfr_1_1SafeThread.html">gbxiceutilacfr::SafeThread</a>, TestThread, TestThreadWithExit, TestThreadWithNap, TestThreadWithThrow, and TestThreadWithWait.</p> <p><a href="classgbxiceutilacfr_1_1Thread-members.html">List of all members.</a></p> <table border="0" cellpadding="0" cellspacing="0"> <tr><td colspan="2"><h2>Public Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classgbxiceutilacfr_1_1Thread.html#aba38342e3f3d907eb8cf41f6c44d3af5">stop</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ab9d7fb32d3d4707a6b9faa30d816a028"></a><!-- doxytag: member="gbxiceutilacfr::Thread::isStopping" ref="ab9d7fb32d3d4707a6b9faa30d816a028" args="()" --> virtual bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classgbxiceutilacfr_1_1Thread.html#ab9d7fb32d3d4707a6b9faa30d816a028">isStopping</a> ()</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Returns TRUE if the thread is in Stopping state, FALSE otherwise. <br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ad386144ecb4f109e80e21252dba321b8"></a><!-- doxytag: member="gbxiceutilacfr::Thread::isStarted" ref="ad386144ecb4f109e80e21252dba321b8" args="()" --> bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classgbxiceutilacfr_1_1Thread.html#ad386144ecb4f109e80e21252dba321b8">isStarted</a> ()</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Returns TRUE if the thread is in Started state, FALSE otherwise. <br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classgbxiceutilacfr_1_1Thread.html#acd42f48f96ef777293db0d2de20cb27b">isActive</a> ()</td></tr> <tr><td colspan="2"><h2>Protected Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classgbxiceutilacfr_1_1Thread.html#a85009d9618c186d77d2285555b573df3">waitForStop</a> ()</td></tr> </table> <hr/><a name="_details"></a><h2>Detailed Description</h2> <p>A minor extention of the IceUtil::Thread class. </p> <p>Adds an option to stop a thread with <a class="el" href="classgbxiceutilacfr_1_1Thread.html#aba38342e3f3d907eb8cf41f6c44d3af5">stop()</a>. Requires that the thread periodically checks whether it has to stop by calling <a class="el" href="classgbxiceutilacfr_1_1Thread.html#ab9d7fb32d3d4707a6b9faa30d816a028" title="Returns TRUE if the thread is in Stopping state, FALSE otherwise.">isStopping()</a>; Since <a class="el" href="classgbxiceutilacfr_1_1Thread.html#aba38342e3f3d907eb8cf41f6c44d3af5">stop()</a> is public, it can be called from inside or outside of the derived class.</p> <p>To use this class, simply overload the virtual IceUtil::Thread::run() function. </p> <div class="fragment"><pre class="fragment"> void MyThread::run() { // initialize // main loop while ( !isStopping() ) { // do something } // clean up } </pre></div><p>The implicit state machine of this class has 4 states {Starting, Running, Stopping, Stopped}. Events and the corresponding state transitions are listed below. Note that the final state may only be accessed when using smart pointer <a class="el" href="namespacegbxiceutilacfr.html#a426649efe8df447b1e04fa1e46efde08" title="A smart pointer to the thread class.">gbxiceutilacfr::ThreadPtr</a> (otherwise the thread self-destructs).</p> <div class="fragment"><pre class="fragment"> EVENT : Constructor IceUtil::Thread::Thread() TRANSITION : Starting INTERNAL : isStopping()=false, isAlive()=false, isStarted()=false EVENT : IceUtil::Thread::start() TRANSITION : Starting -> Running INTERNAL : isStopping()=false, isAlive()=true, isStarted()=true EVENT : gbxiceutilacfr::Thread::stop() TRANSITION : Running -> Stopping INTERNAL : isStopping()=true, isAlive()=true, isStarted()=true EVENT : termination of run() function. TRANSITION : Stopping -> Stopped INTERNAL : isStopping()=true, isAlive()=false, isStarted()=true </pre></div><p>Caveats:</p> <ul> <li>Make sure you catch all exception which can possibly be raised inside IceUtil::Thread::run. Otherwise, you'll see "uncaught exception" printed out and the component will hang.</li> <li>gbxiceutilacfr::Threads self-destruct (ie call their own destructor) when gbxiceutilacfr::Thread::run returns, unless you hold onto an <a class="el" href="namespacegbxiceutilacfr.html#a426649efe8df447b1e04fa1e46efde08" title="A smart pointer to the thread class.">gbxiceutilacfr::ThreadPtr</a> which points to it. So never call <code>delete</code> on the pointer to a thread, doing so will result in segmentation fault.</li> </ul> <dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classgbxiceutilacfr_1_1SafeThread.html" title="A version of the Thread class which catches all possible exceptions.">SafeThread</a> </dd></dl> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="acd42f48f96ef777293db0d2de20cb27b"></a><!-- doxytag: member="gbxiceutilacfr::Thread::isActive" ref="acd42f48f96ef777293db0d2de20cb27b" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool gbxiceutilacfr::Thread::isActive </td> <td>(</td> <td class="paramname"></td> <td> ) </td> <td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p><b>Depricated</b> function! Use <a class="el" href="classgbxiceutilacfr_1_1Thread.html#ab9d7fb32d3d4707a6b9faa30d816a028" title="Returns TRUE if the thread is in Stopping state, FALSE otherwise.">isStopping()</a> instead (note that it returns the opposite).</p> <p>Returns FALSE if thread was told to stop, TRUE otherwise. </p> <p>References <a class="el" href="thread_8cpp_source.html#l00039">isStopping()</a>.</p> </div> </div> <a class="anchor" id="aba38342e3f3d907eb8cf41f6c44d3af5"></a><!-- doxytag: member="gbxiceutilacfr::Thread::stop" ref="aba38342e3f3d907eb8cf41f6c44d3af5" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void gbxiceutilacfr::Thread::stop </td> <td>(</td> <td class="paramname"></td> <td> ) </td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Lets the thread know that it's time to stop. Thread-safe, so it can be called from inside or outside this thread. </p> </div> </div> <a class="anchor" id="a85009d9618c186d77d2285555b573df3"></a><!-- doxytag: member="gbxiceutilacfr::Thread::waitForStop" ref="a85009d9618c186d77d2285555b573df3" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void gbxiceutilacfr::Thread::waitForStop </td> <td>(</td> <td class="paramname"></td> <td> ) </td> <td><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Wait for someone from the outside to call <a class="el" href="classgbxiceutilacfr_1_1Thread.html#aba38342e3f3d907eb8cf41f6c44d3af5">stop</a>. It may be necessary to call this function before exitting from IceUtil::Thread::run after catching an exception. If we just exit from run() and someone calls our <a class="el" href="classgbxiceutilacfr_1_1Thread.html#aba38342e3f3d907eb8cf41f6c44d3af5">stop()</a> function afterwards there's a possibility of lock up. </p> <p>References <a class="el" href="thread_8cpp_source.html#l00039">isStopping()</a>.</p> <p>Referenced by <a class="el" href="safethread_8cpp_source.html#l00026">gbxiceutilacfr::SafeThread::run()</a>.</p> </div> </div> <hr/>The documentation for this class was generated from the following files:<ul> <li><a class="el" href="thread_8h_source.html">thread.h</a></li> <li>thread.cpp</li> </ul> </div> </td> <td colspan="1"> </td> </tr> </table> <!-- end of table --> <hr size="1"><address style="align: right;"><small>Generated for GearBox by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.5 </small></address> </body> </html>