Sophie

Sophie

distrib > Mandriva > 2010.0 > x86_64 > by-pkgid > 7f3e5f74d754b480ec33648905c4afae > files > 140

glibmm2.4-doc-2.22.1-1mdv2010.0.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>glibmm: Glib::Cond Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;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="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceGlib.html">Glib</a>::<a class="el" href="classGlib_1_1Cond.html">Cond</a>
  </div>
</div>
<div class="contents">
<h1>Glib::Cond Class Reference<br/>
<small>
[<a class="el" href="group__Threads.html">Threads</a>]</small>
</h1><!-- doxytag: class="Glib::Cond" -->
<p>An opaque data structure to represent a condition. <a href="#_details">More...</a></p>

<p><a href="classGlib_1_1Cond-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">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Cond.html#a2182b1171de3bdd0b97ab2f16d88a17a">Cond</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Cond.html#a67919ec3f33e19185f72d9c1a0043605">~Cond</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Cond.html#a072cb37a06a695b54370209bc3280f4d">signal</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">If threads are waiting for this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>, exactly one of them is woken up. <a href="#a072cb37a06a695b54370209bc3280f4d"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Cond.html#a2ed0ec9fc4e29140f8854a05bfb5df3b">broadcast</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">If threads are waiting for this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>, all of them are woken up. <a href="#a2ed0ec9fc4e29140f8854a05bfb5df3b"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Cond.html#ae989bf2891954ff5ed745f447cdccf2a">wait</a> (<a class="el" href="classGlib_1_1Mutex.html">Mutex</a>&amp; mutex)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Waits until this thread is woken up on this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>. <a href="#ae989bf2891954ff5ed745f447cdccf2a"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Cond.html#acb37b09bf04ae36e30ec32c2f3d4af69">timed_wait</a> (<a class="el" href="classGlib_1_1Mutex.html">Mutex</a>&amp; mutex, const <a class="el" href="structGlib_1_1TimeVal.html">Glib::TimeVal</a>&amp; abs_time)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Waits until this thread is woken up on this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>, but not longer than until the time, that is specified by <em>abs_time</em>. <a href="#acb37b09bf04ae36e30ec32c2f3d4af69"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">GCond*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Cond.html#a27a794031bc8a6c104db3b9977254c61">gobj</a> ()</td></tr>
</table>
<hr/><a name="_details"></a><h2>Detailed Description</h2>
<p>An opaque data structure to represent a condition. </p>
<p>A <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em> is an object that threads can block on, if they find a certain condition to be false. If other threads change the state of this condition they can signal the <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>, such that the waiting thread is woken up. </p>
<dl class="user"><dt><b>Usage example:</b></dt><dd><div class="fragment"><pre class="fragment"> <a class="code" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Glib::Cond</a> data_cond;
 <a class="code" href="classGlib_1_1Mutex.html" title="Represents a mutex (mutual exclusion).">Glib::Mutex</a> data_mutex;
 <span class="keywordtype">void</span>* current_data = 0;

 <span class="keywordtype">void</span> push_data(<span class="keywordtype">void</span>* data)
 {
   <a class="code" href="classGlib_1_1Mutex_1_1Lock.html" title="Utility class for exception-safe mutex locking.">Glib::Mutex::Lock</a> <a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01002.html#ga2bdabeb51d7e55d6358ad0857843ebea">lock</a> (data_mutex);

   current_data = data;
   data_cond.<a class="code" href="classGlib_1_1Cond.html#a072cb37a06a695b54370209bc3280f4d" title="If threads are waiting for this Cond, exactly one of them is woken up.">signal</a>();
 }

 <span class="keywordtype">void</span>* pop_data()
 {
   <a class="code" href="classGlib_1_1Mutex_1_1Lock.html" title="Utility class for exception-safe mutex locking.">Glib::Mutex::Lock</a> <a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01002.html#ga2bdabeb51d7e55d6358ad0857843ebea">lock</a> (data_mutex);

   <span class="keywordflow">while</span> (!current_data)
     data_cond.<a class="code" href="classGlib_1_1Cond.html#ae989bf2891954ff5ed745f447cdccf2a" title="Waits until this thread is woken up on this Cond.">wait</a>(data_mutex);

   <span class="keywordtype">void</span> *<span class="keyword">const</span> data = current_data;
   current_data = 0;

   <span class="keywordflow">return</span> data;
 }
</pre></div> </dd></dl>
<dl><dt><b>Examples: </b></dt><dd>
<p><a class="el" href="thread_2thread_8cc-example.html#_a2">thread/thread.cc</a>.</p>
</dd>
</dl><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a2182b1171de3bdd0b97ab2f16d88a17a"></a><!-- doxytag: member="Glib::Cond::Cond" ref="a2182b1171de3bdd0b97ab2f16d88a17a" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Glib::Cond::Cond </td>
          <td>(</td>
          <td class="paramname"></td>
          <td>&#160;)&#160;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<a class="anchor" id="a67919ec3f33e19185f72d9c1a0043605"></a><!-- doxytag: member="Glib::Cond::~Cond" ref="a67919ec3f33e19185f72d9c1a0043605" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Glib::Cond::~Cond </td>
          <td>(</td>
          <td class="paramname"></td>
          <td>&#160;)&#160;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a2ed0ec9fc4e29140f8854a05bfb5df3b"></a><!-- doxytag: member="Glib::Cond::broadcast" ref="a2ed0ec9fc4e29140f8854a05bfb5df3b" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Glib::Cond::broadcast </td>
          <td>(</td>
          <td class="paramname"></td>
          <td>&#160;)&#160;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>If threads are waiting for this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>, all of them are woken up. </p>
<p>It is good practice to hold the same lock as the waiting thread, while calling this method, though not required.</p>
<dl class="note"><dt><b>Note:</b></dt><dd>This method can also be used if <em><a class="el" href="group__Threads.html#gab26d01c776801f1fff00753e97af4fc7" title="Initializes the GLib thread system.">Glib::thread_init()</a></em> has not yet been called and will do nothing then. </dd></dl>

</div>
</div>
<a class="anchor" id="a27a794031bc8a6c104db3b9977254c61"></a><!-- doxytag: member="Glib::Cond::gobj" ref="a27a794031bc8a6c104db3b9977254c61" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">GCond* Glib::Cond::gobj </td>
          <td>(</td>
          <td class="paramname"></td>
          <td>&#160;)&#160;</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<a class="anchor" id="a072cb37a06a695b54370209bc3280f4d"></a><!-- doxytag: member="Glib::Cond::signal" ref="a072cb37a06a695b54370209bc3280f4d" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Glib::Cond::signal </td>
          <td>(</td>
          <td class="paramname"></td>
          <td>&#160;)&#160;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>If threads are waiting for this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>, exactly one of them is woken up. </p>
<p>It is good practice to hold the same lock as the waiting thread, while calling this method, though not required.</p>
<dl class="note"><dt><b>Note:</b></dt><dd>This method can also be used if <em><a class="el" href="group__Threads.html#gab26d01c776801f1fff00753e97af4fc7" title="Initializes the GLib thread system.">Glib::thread_init()</a></em> has not yet been called and will do nothing then. </dd></dl>

</div>
</div>
<a class="anchor" id="acb37b09bf04ae36e30ec32c2f3d4af69"></a><!-- doxytag: member="Glib::Cond::timed_wait" ref="acb37b09bf04ae36e30ec32c2f3d4af69" args="(Mutex &amp;mutex, const Glib::TimeVal &amp;abs_time)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Glib::Cond::timed_wait </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classGlib_1_1Mutex.html">Mutex</a>&amp;&#160;</td>
          <td class="paramname"> <em>mutex</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structGlib_1_1TimeVal.html">Glib::TimeVal</a>&amp;&#160;</td>
          <td class="paramname"> <em>abs_time</em></td><td>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Waits until this thread is woken up on this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>, but not longer than until the time, that is specified by <em>abs_time</em>. </p>
<p>The mutex is unlocked before falling asleep and locked again before resuming.</p>
<p>This function can also be used, if <em><a class="el" href="group__Threads.html#gab26d01c776801f1fff00753e97af4fc7" title="Initializes the GLib thread system.">Glib::thread_init()</a></em> has not yet been called and will immediately return <code>true</code> then.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>mutex</em>&#160;</td><td>a <em><a class="el" href="classGlib_1_1Mutex.html" title="Represents a mutex (mutual exclusion).">Mutex</a></em> that is currently locked. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>abs_time</em>&#160;</td><td>a max time to wait.</td></tr>
  </table>
  </dd>
</dl>
<dl class="note"><dt><b>Note:</b></dt><dd>It is important to use the <em><a class="el" href="classGlib_1_1Cond.html#ae989bf2891954ff5ed745f447cdccf2a" title="Waits until this thread is woken up on this Cond.">wait()</a></em> and <em><a class="el" href="classGlib_1_1Cond.html#acb37b09bf04ae36e30ec32c2f3d4af69" title="Waits until this thread is woken up on this Cond, but not longer than until the time...">timed_wait()</a></em> methods only inside a loop, which checks for the condition to be true as it is not guaranteed that the waiting thread will find it fulfilled, even if the signaling thread left the condition in that state. This is because another thread can have altered the condition, before the waiting thread got the chance to be woken up, even if the condition itself is protected by a <em><a class="el" href="classGlib_1_1Mutex.html" title="Represents a mutex (mutual exclusion).">Mutex</a></em>. </dd></dl>

</div>
</div>
<a class="anchor" id="ae989bf2891954ff5ed745f447cdccf2a"></a><!-- doxytag: member="Glib::Cond::wait" ref="ae989bf2891954ff5ed745f447cdccf2a" args="(Mutex &amp;mutex)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Glib::Cond::wait </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classGlib_1_1Mutex.html">Mutex</a>&amp;&#160;</td>
          <td class="paramname"> <em>mutex</em></td>
          <td>&#160;)&#160;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Waits until this thread is woken up on this <em><a class="el" href="classGlib_1_1Cond.html" title="An opaque data structure to represent a condition.">Cond</a></em>. </p>
<p>The mutex is unlocked before falling asleep and locked again before resuming.</p>
<p>This method can also be used if <em><a class="el" href="group__Threads.html#gab26d01c776801f1fff00753e97af4fc7" title="Initializes the GLib thread system.">Glib::thread_init()</a></em> has not yet been called and will immediately return then.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>mutex</em>&#160;</td><td>a <em><a class="el" href="classGlib_1_1Mutex.html" title="Represents a mutex (mutual exclusion).">Mutex</a></em> that is currently locked.</td></tr>
  </table>
  </dd>
</dl>
<dl class="note"><dt><b>Note:</b></dt><dd>It is important to use the <em><a class="el" href="classGlib_1_1Cond.html#ae989bf2891954ff5ed745f447cdccf2a" title="Waits until this thread is woken up on this Cond.">wait()</a></em> and <em><a class="el" href="classGlib_1_1Cond.html#acb37b09bf04ae36e30ec32c2f3d4af69" title="Waits until this thread is woken up on this Cond, but not longer than until the time...">timed_wait()</a></em> methods only inside a loop, which checks for the condition to be true as it is not guaranteed that the waiting thread will find it fulfilled, even if the signaling thread left the condition in that state. This is because another thread can have altered the condition, before the waiting thread got the chance to be woken up, even if the condition itself is protected by a <em><a class="el" href="classGlib_1_1Mutex.html" title="Represents a mutex (mutual exclusion).">Mutex</a></em>. </dd></dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>glibmm/thread.h</li>
</ul>
</div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Mon Sep 21 11:07:25 2009 for glibmm by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>