1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
<!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"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.7"/>
<title>glibmm: Glib::Threads::Cond Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">glibmm
 <span id="projectnumber">2.42.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.7 -->
<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 class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="annotated.html"><span>Class List</span></a></li>
<li><a href="classes.html"><span>Class Index</span></a></li>
<li><a href="inherits.html"><span>Class Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class Members</span></a></li>
</ul>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="namespaceGlib.html">Glib</a></li><li class="navelem"><a class="el" href="namespaceGlib_1_1Threads.html">Threads</a></li><li class="navelem"><a class="el" href="classGlib_1_1Threads_1_1Cond.html">Cond</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> |
<a href="classGlib_1_1Threads_1_1Cond-members.html">List of all members</a> </div>
<div class="headertitle">
<div class="title">Glib::Threads::Cond Class Reference<div class="ingroups"><a class="el" href="group__Threads.html">Threads</a></div></div> </div>
</div><!--header-->
<div class="contents">
<p>An opaque data structure to represent a condition.
<a href="classGlib_1_1Threads_1_1Cond.html#details">More...</a></p>
<p><code>#include <glibmm/threads.h></code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a1a61666d7577c6ac28232c388923aa42"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Threads_1_1Cond.html#a1a61666d7577c6ac28232c388923aa42">Cond</a> ()</td></tr>
<tr class="separator:a1a61666d7577c6ac28232c388923aa42"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a674e83a368694681ad7f145512e79055"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Threads_1_1Cond.html#a674e83a368694681ad7f145512e79055">~Cond</a> ()</td></tr>
<tr class="separator:a674e83a368694681ad7f145512e79055"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a9db57dd8e743968ee7ac6932d0acabf5"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Threads_1_1Cond.html#a9db57dd8e743968ee7ac6932d0acabf5">signal</a> ()</td></tr>
<tr class="memdesc:a9db57dd8e743968ee7ac6932d0acabf5"><td class="mdescLeft"> </td><td class="mdescRight">If threads are waiting for this <em><a class="el" href="classGlib_1_1Threads_1_1Cond.html" title="An opaque data structure to represent a condition. ">Cond</a></em>, exactly one of them is woken up. <a href="#a9db57dd8e743968ee7ac6932d0acabf5">More...</a><br /></td></tr>
<tr class="separator:a9db57dd8e743968ee7ac6932d0acabf5"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ac59292a7e51e8e6cc85bcdd071c982e1"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Threads_1_1Cond.html#ac59292a7e51e8e6cc85bcdd071c982e1">broadcast</a> ()</td></tr>
<tr class="memdesc:ac59292a7e51e8e6cc85bcdd071c982e1"><td class="mdescLeft"> </td><td class="mdescRight">If threads are waiting for this <em><a class="el" href="classGlib_1_1Threads_1_1Cond.html" title="An opaque data structure to represent a condition. ">Cond</a></em>, all of them are woken up. <a href="#ac59292a7e51e8e6cc85bcdd071c982e1">More...</a><br /></td></tr>
<tr class="separator:ac59292a7e51e8e6cc85bcdd071c982e1"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a08e9c45266817a95001135e2b7698598"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Threads_1_1Cond.html#a08e9c45266817a95001135e2b7698598">wait</a> (<a class="el" href="classGlib_1_1Threads_1_1Mutex.html">Mutex</a>& mutex)</td></tr>
<tr class="memdesc:a08e9c45266817a95001135e2b7698598"><td class="mdescLeft"> </td><td class="mdescRight">Waits until this thread is woken up on this <em><a class="el" href="classGlib_1_1Threads_1_1Cond.html" title="An opaque data structure to represent a condition. ">Cond</a></em>. <a href="#a08e9c45266817a95001135e2b7698598">More...</a><br /></td></tr>
<tr class="separator:a08e9c45266817a95001135e2b7698598"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ab8c8842a5962291411b67abd9bb4746d"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Threads_1_1Cond.html#ab8c8842a5962291411b67abd9bb4746d">wait_until</a> (<a class="el" href="classGlib_1_1Threads_1_1Mutex.html">Mutex</a>& mutex, gint64 end_time)</td></tr>
<tr class="memdesc:ab8c8842a5962291411b67abd9bb4746d"><td class="mdescLeft"> </td><td class="mdescRight">Waits until this thread is woken up on this <em><a class="el" href="classGlib_1_1Threads_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>end_time</em>. <a href="#ab8c8842a5962291411b67abd9bb4746d">More...</a><br /></td></tr>
<tr class="separator:ab8c8842a5962291411b67abd9bb4746d"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a74fd007fcce8d7e40322289b46d746a5"><td class="memItemLeft" align="right" valign="top">GCond* </td><td class="memItemRight" valign="bottom"><a class="el" href="classGlib_1_1Threads_1_1Cond.html#a74fd007fcce8d7e40322289b46d746a5">gobj</a> ()</td></tr>
<tr class="separator:a74fd007fcce8d7e40322289b46d746a5"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>An opaque data structure to represent a condition. </p>
<p>A <em><a class="el" href="classGlib_1_1Threads_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_1Threads_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="section user"><dt>Usage example:</dt><dd><div class="fragment"><div class="line"><a class="code" href="classGlib_1_1Cond.html">Glib::Cond</a> data_cond;</div>
<div class="line"><a class="code" href="classGlib_1_1Mutex.html">Glib::Mutex</a> data_mutex;</div>
<div class="line"><span class="keywordtype">void</span>* current_data = 0;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> push_data(<span class="keywordtype">void</span>* data)</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="classGlib_1_1Mutex_1_1Lock.html">Glib::Mutex::Lock</a> <a class="codeRef" doxygen="/opt/gnome/share/mm-common/doctags/libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01650.html#ga24630a7020b341d48604f46e9eb210cd">lock</a> (data_mutex);</div>
<div class="line"></div>
<div class="line"> current_data = data;</div>
<div class="line"> data_cond.<a class="code" href="classGlib_1_1Cond.html#a072cb37a06a695b54370209bc3280f4d">signal</a>();</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span>* pop_data()</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="classGlib_1_1Mutex_1_1Lock.html">Glib::Mutex::Lock</a> <a class="codeRef" doxygen="/opt/gnome/share/mm-common/doctags/libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01650.html#ga24630a7020b341d48604f46e9eb210cd">lock</a> (data_mutex);</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">while</span> (!current_data)</div>
<div class="line"> data_cond.<a class="code" href="classGlib_1_1Cond.html#ae989bf2891954ff5ed745f447cdccf2a">wait</a>(data_mutex);</div>
<div class="line"></div>
<div class="line"> <span class="keywordtype">void</span> *<span class="keyword">const</span> data = current_data;</div>
<div class="line"> current_data = 0;</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> data;</div>
<div class="line">}</div>
</div><!-- fragment --> </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="thread_2thread_8cc-example.html#_a1">thread/thread.cc</a>.</dd>
</dl></div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a class="anchor" id="a1a61666d7577c6ac28232c388923aa42"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">Glib::Threads::Cond::Cond </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a class="anchor" id="a674e83a368694681ad7f145512e79055"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">Glib::Threads::Cond::~Cond </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="ac59292a7e51e8e6cc85bcdd071c982e1"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Glib::Threads::Cond::broadcast </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>If threads are waiting for this <em><a class="el" href="classGlib_1_1Threads_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>
</div>
</div>
<a class="anchor" id="a74fd007fcce8d7e40322289b46d746a5"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">GCond* Glib::Threads::Cond::gobj </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a class="anchor" id="a9db57dd8e743968ee7ac6932d0acabf5"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Glib::Threads::Cond::signal </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>If threads are waiting for this <em><a class="el" href="classGlib_1_1Threads_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>
</div>
</div>
<a class="anchor" id="a08e9c45266817a95001135e2b7698598"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void Glib::Threads::Cond::wait </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classGlib_1_1Threads_1_1Mutex.html">Mutex</a>& </td>
<td class="paramname"><em>mutex</em></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_1Threads_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>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">mutex</td><td>a <em><a class="el" href="classGlib_1_1Threads_1_1Mutex.html" title="Represents a mutex (mutual exclusion). ">Mutex</a></em> that is currently locked.</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>It is important to use the <em><a class="el" href="classGlib_1_1Threads_1_1Cond.html#a08e9c45266817a95001135e2b7698598" title="Waits until this thread is woken up on this Cond. ">wait()</a></em> and <em><a class="el" href="classGlib_1_1Threads_1_1Cond.html#ab8c8842a5962291411b67abd9bb4746d" title="Waits until this thread is woken up on this Cond, but not longer than until the time, that is specified by end_time. ">wait_until()</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_1Threads_1_1Mutex.html" title="Represents a mutex (mutual exclusion). ">Mutex</a></em>. </dd></dl>
</div>
</div>
<a class="anchor" id="ab8c8842a5962291411b67abd9bb4746d"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool Glib::Threads::Cond::wait_until </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classGlib_1_1Threads_1_1Mutex.html">Mutex</a>& </td>
<td class="paramname"><em>mutex</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">gint64 </td>
<td class="paramname"><em>end_time</em> </td>
</tr>
<tr>
<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_1Threads_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>end_time</em>. </p>
<p>The mutex is unlocked before falling asleep and locked again before resuming.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">mutex</td><td>a <em><a class="el" href="classGlib_1_1Threads_1_1Mutex.html" title="Represents a mutex (mutual exclusion). ">Mutex</a></em> that is currently locked. </td></tr>
<tr><td class="paramname">end_time</td><td>a max time to wait.</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>It is important to use the <em><a class="el" href="classGlib_1_1Threads_1_1Cond.html#a08e9c45266817a95001135e2b7698598" title="Waits until this thread is woken up on this Cond. ">wait()</a></em> and <em><a class="el" href="classGlib_1_1Threads_1_1Cond.html#ab8c8842a5962291411b67abd9bb4746d" title="Waits until this thread is woken up on this Cond, but not longer than until the time, that is specified by end_time. ">wait_until()</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_1Threads_1_1Mutex.html" title="Represents a mutex (mutual exclusion). ">Mutex</a></em>. </dd></dl>
</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Mon Sep 22 2014 21:38:34 for glibmm by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.7
</small></address>
</body>
</html>
|