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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
<!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"/>
<title>wxWidgets: wxCondition 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" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
<tbody>
<tr>
<td id="projectlogo">
<a href="http://www.wxwidgets.org/" target="_new">
<img alt="wxWidgets" src="logo.png"/>
</a>
</td>
<td style="padding-left: 0.5em; text-align: right;">
<span id="projectnumber">Version: 3.0.2</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
<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>Categories</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>
</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="hierarchy.html"><span>Class Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class Members</span></a></li>
</ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> |
<a href="classwx_condition-members.html">List of all members</a> </div>
<div class="headertitle">
<div class="title">wxCondition Class Reference<div class="ingroups"><a class="el" href="group__group__class__threading.html">Threading</a></div></div> </div>
</div><!--header-->
<div class="contents">
<p><code>#include <wx/thread.h></code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p><a class="el" href="classwx_condition.html" title="wxCondition variables correspond to pthread conditions or to Win32 event objects.">wxCondition</a> variables correspond to pthread conditions or to Win32 event objects. </p>
<p>They may be used in a multithreaded application to wait until the given condition becomes <span class="literal">true</span> which happens when the condition becomes signaled.</p>
<p>For example, if a worker thread is doing some long task and another thread has to wait until it is finished, the latter thread will wait on the condition object and the worker thread will signal it on exit (this example is not perfect because in this particular case it would be much better to just <a class="el" href="classwx_thread.html#a62ee778033013d3a4754b71b8cf2902e" title="Waits for a joinable thread to terminate and returns the value the thread returned from Entry() or "(...">wxThread::Wait</a> for the worker thread, but if there are several worker threads it already makes much more sense).</p>
<p>Note that a call to <a class="el" href="classwx_condition.html#a9fa920a093abdadb19f40db82fbaedd4" title="Signals the object waking up at most one thread.">wxCondition::Signal</a> may happen before the other thread calls <a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">wxCondition::Wait</a> and, just as with the pthread conditions, the signal is then lost and so if you want to be sure that you don't miss it you must keep the mutex associated with the condition initially locked and lock it again before calling <a class="el" href="classwx_condition.html#a9fa920a093abdadb19f40db82fbaedd4" title="Signals the object waking up at most one thread.">wxCondition::Signal</a>. Of course, this means that this call is going to block until <a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">wxCondition::Wait</a> is called by another thread.</p>
<h1><a class="anchor" id="condition_example"></a>
Example</h1>
<p>This example shows how a main thread may launch a worker thread which starts running and then waits until the main thread signals it to continue:</p>
<div class="fragment"><div class="line"><span class="keyword">class </span>MySignallingThread : <span class="keyword">public</span> <a class="code" href="classwx_thread.html" title="A thread is basically a path of execution through a program.">wxThread</a></div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> MySignallingThread(<a class="code" href="classwx_mutex.html" title="A mutex object is a synchronization object whose state is set to signaled when it is not owned by any...">wxMutex</a> *mutex, <a class="code" href="classwx_condition.html" title="wxCondition variables correspond to pthread conditions or to Win32 event objects.">wxCondition</a> *condition)</div>
<div class="line"> {</div>
<div class="line"> m_mutex = mutex;</div>
<div class="line"> m_condition = condition;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="keyword">virtual</span> ExitCode Entry()</div>
<div class="line"> {</div>
<div class="line"> ... <span class="keywordflow">do</span> our job ...</div>
<div class="line"></div>
<div class="line"> <span class="comment">// tell the other(s) thread(s) that we're about to terminate: we must</span></div>
<div class="line"> <span class="comment">// lock the mutex first or we might signal the condition before the</span></div>
<div class="line"> <span class="comment">// waiting threads start waiting on it!</span></div>
<div class="line"> <a class="code" href="classwx_mutex_locker.html" title="This is a small helper class to be used with wxMutex objects.">wxMutexLocker</a> lock(*m_mutex);</div>
<div class="line"> m_condition->Broadcast(); <span class="comment">// same as Signal() here -- one waiter only</span></div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"><span class="keyword">private</span>:</div>
<div class="line"> <a class="code" href="classwx_condition.html" title="wxCondition variables correspond to pthread conditions or to Win32 event objects.">wxCondition</a> *m_condition;</div>
<div class="line"> <a class="code" href="classwx_mutex.html" title="A mutex object is a synchronization object whose state is set to signaled when it is not owned by any...">wxMutex</a> *m_mutex;</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="classwx_mutex.html" title="A mutex object is a synchronization object whose state is set to signaled when it is not owned by any...">wxMutex</a> mutex;</div>
<div class="line"> <a class="code" href="classwx_condition.html" title="wxCondition variables correspond to pthread conditions or to Win32 event objects.">wxCondition</a> condition(mutex);</div>
<div class="line"></div>
<div class="line"> <span class="comment">// the mutex should be initially locked</span></div>
<div class="line"> mutex.<a class="code" href="classwx_mutex.html#a5291e0e421262f420051390421ba0d09" title="Locks the mutex object.">Lock</a>();</div>
<div class="line"></div>
<div class="line"> <span class="comment">// create and run the thread but notice that it won't be able to</span></div>
<div class="line"> <span class="comment">// exit (and signal its exit) before we unlock the mutex below</span></div>
<div class="line"> MySignallingThread *thread = <span class="keyword">new</span> MySignallingThread(&mutex, &condition);</div>
<div class="line"></div>
<div class="line"> thread->Run();</div>
<div class="line"></div>
<div class="line"> <span class="comment">// wait for the thread termination: Wait() atomically unlocks the mutex</span></div>
<div class="line"> <span class="comment">// which allows the thread to continue and starts waiting</span></div>
<div class="line"> condition.Wait();</div>
<div class="line"></div>
<div class="line"> <span class="comment">// now we can exit</span></div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p>Of course, here it would be much better to simply use a joinable thread and call <a class="el" href="classwx_thread.html#a62ee778033013d3a4754b71b8cf2902e" title="Waits for a joinable thread to terminate and returns the value the thread returned from Entry() or "(...">wxThread::Wait</a> on it, but this example does illustrate the importance of properly locking the mutex when using <a class="el" href="classwx_condition.html" title="wxCondition variables correspond to pthread conditions or to Win32 event objects.">wxCondition</a>.</p>
<h2></h2>
<div><span class="lib">Library:</span>  <span class="lib_text"><a class="el" href="page_libs.html#page_libs_wxbase">wxBase</a></span></div><div><span class="category">Category:</span>  <span class="category_text"><a class="el" href="group__group__class__threading.html">Threading</a></span></div><dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_thread.html" title="A thread is basically a path of execution through a program.">wxThread</a>, <a class="el" href="classwx_mutex.html" title="A mutex object is a synchronization object whose state is set to signaled when it is not owned by any...">wxMutex</a> </dd></dl>
</div><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:a0c73d224b294846ef9358cfaa36b573e"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_condition.html#a0c73d224b294846ef9358cfaa36b573e">wxCondition</a> (<a class="el" href="classwx_mutex.html">wxMutex</a> &mutex)</td></tr>
<tr class="memdesc:a0c73d224b294846ef9358cfaa36b573e"><td class="mdescLeft"> </td><td class="mdescRight">Default and only constructor. <a href="#a0c73d224b294846ef9358cfaa36b573e"></a><br/></td></tr>
<tr class="separator:a0c73d224b294846ef9358cfaa36b573e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a78c0da35a4bc0a611039b105ff839ea1"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_condition.html#a78c0da35a4bc0a611039b105ff839ea1">~wxCondition</a> ()</td></tr>
<tr class="memdesc:a78c0da35a4bc0a611039b105ff839ea1"><td class="mdescLeft"> </td><td class="mdescRight">Destroys the <a class="el" href="classwx_condition.html" title="wxCondition variables correspond to pthread conditions or to Win32 event objects.">wxCondition</a> object. <a href="#a78c0da35a4bc0a611039b105ff839ea1"></a><br/></td></tr>
<tr class="separator:a78c0da35a4bc0a611039b105ff839ea1"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:af8ed8df7255aba60dcecba0bbe102fd4"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_condition.html#af8ed8df7255aba60dcecba0bbe102fd4">Broadcast</a> ()</td></tr>
<tr class="memdesc:af8ed8df7255aba60dcecba0bbe102fd4"><td class="mdescLeft"> </td><td class="mdescRight">Broadcasts to all waiting threads, waking all of them up. <a href="#af8ed8df7255aba60dcecba0bbe102fd4"></a><br/></td></tr>
<tr class="separator:af8ed8df7255aba60dcecba0bbe102fd4"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ae1ccee596e1b527821f2d084d2f4b5e4"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_condition.html#ae1ccee596e1b527821f2d084d2f4b5e4">IsOk</a> () const </td></tr>
<tr class="memdesc:ae1ccee596e1b527821f2d084d2f4b5e4"><td class="mdescLeft"> </td><td class="mdescRight">Returns <span class="literal">true</span> if the object had been initialized successfully, <span class="literal">false</span> if an error occurred. <a href="#ae1ccee596e1b527821f2d084d2f4b5e4"></a><br/></td></tr>
<tr class="separator:ae1ccee596e1b527821f2d084d2f4b5e4"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a9fa920a093abdadb19f40db82fbaedd4"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_condition.html#a9fa920a093abdadb19f40db82fbaedd4">Signal</a> ()</td></tr>
<tr class="memdesc:a9fa920a093abdadb19f40db82fbaedd4"><td class="mdescLeft"> </td><td class="mdescRight">Signals the object waking up at most one thread. <a href="#a9fa920a093abdadb19f40db82fbaedd4"></a><br/></td></tr>
<tr class="separator:a9fa920a093abdadb19f40db82fbaedd4"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ad42af860d727aad40cf366eaab9da48d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d">Wait</a> ()</td></tr>
<tr class="memdesc:ad42af860d727aad40cf366eaab9da48d"><td class="mdescLeft"> </td><td class="mdescRight">Waits until the condition is signalled. <a href="#ad42af860d727aad40cf366eaab9da48d"></a><br/></td></tr>
<tr class="separator:ad42af860d727aad40cf366eaab9da48d"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:af7379efa6047603779717ec8fd4c95c9"><td class="memTemplParams" colspan="2">template<typename Functor > </td></tr>
<tr class="memitem:af7379efa6047603779717ec8fd4c95c9"><td class="memTemplItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classwx_condition.html#af7379efa6047603779717ec8fd4c95c9">Wait</a> (const Functor &predicate)</td></tr>
<tr class="memdesc:af7379efa6047603779717ec8fd4c95c9"><td class="mdescLeft"> </td><td class="mdescRight">Waits until the condition is signalled and the associated condition true. <a href="#af7379efa6047603779717ec8fd4c95c9"></a><br/></td></tr>
<tr class="separator:af7379efa6047603779717ec8fd4c95c9"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a368e40158c732759fad60d46d292bd2d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_condition.html#a368e40158c732759fad60d46d292bd2d">WaitTimeout</a> (unsigned long milliseconds)</td></tr>
<tr class="memdesc:a368e40158c732759fad60d46d292bd2d"><td class="mdescLeft"> </td><td class="mdescRight">Waits until the condition is signalled or the timeout has elapsed. <a href="#a368e40158c732759fad60d46d292bd2d"></a><br/></td></tr>
<tr class="separator:a368e40158c732759fad60d46d292bd2d"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a class="anchor" id="a0c73d224b294846ef9358cfaa36b573e"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">wxCondition::wxCondition </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classwx_mutex.html">wxMutex</a> & </td>
<td class="paramname"><em>mutex</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Default and only constructor. </p>
<p>The <em>mutex</em> must be locked by the caller before calling <a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">Wait()</a> function. Use <a class="el" href="classwx_condition.html#ae1ccee596e1b527821f2d084d2f4b5e4" title="Returns true if the object had been initialized successfully, false if an error occurred.">IsOk()</a> to check if the object was successfully initialized. </p>
</div>
</div>
<a class="anchor" id="a78c0da35a4bc0a611039b105ff839ea1"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">wxCondition::~wxCondition </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Destroys the <a class="el" href="classwx_condition.html" title="wxCondition variables correspond to pthread conditions or to Win32 event objects.">wxCondition</a> object. </p>
<p>The destructor is not virtual so this class should not be used polymorphically. </p>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="af8ed8df7255aba60dcecba0bbe102fd4"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> wxCondition::Broadcast </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Broadcasts to all waiting threads, waking all of them up. </p>
<p>Note that this method may be called whether the mutex associated with this condition is locked or not.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_condition.html#a9fa920a093abdadb19f40db82fbaedd4" title="Signals the object waking up at most one thread.">Signal()</a> </dd></dl>
</div>
</div>
<a class="anchor" id="ae1ccee596e1b527821f2d084d2f4b5e4"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool wxCondition::IsOk </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns <span class="literal">true</span> if the object had been initialized successfully, <span class="literal">false</span> if an error occurred. </p>
</div>
</div>
<a class="anchor" id="a9fa920a093abdadb19f40db82fbaedd4"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> wxCondition::Signal </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Signals the object waking up at most one thread. </p>
<p>If several threads are waiting on the same condition, the exact thread which is woken up is undefined. If no threads are waiting, the signal is lost and the condition would have to be signalled again to wake up any thread which may start waiting on it later.</p>
<p>Note that this method may be called whether the mutex associated with this condition is locked or not.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_condition.html#af8ed8df7255aba60dcecba0bbe102fd4" title="Broadcasts to all waiting threads, waking all of them up.">Broadcast()</a> </dd></dl>
</div>
</div>
<a class="anchor" id="ad42af860d727aad40cf366eaab9da48d"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> wxCondition::Wait </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Waits until the condition is signalled. </p>
<p>This method atomically releases the lock on the mutex associated with this condition (this is why it must be locked prior to calling <a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">Wait()</a>) and puts the thread to sleep until <a class="el" href="classwx_condition.html#a9fa920a093abdadb19f40db82fbaedd4" title="Signals the object waking up at most one thread.">Signal()</a> or <a class="el" href="classwx_condition.html#af8ed8df7255aba60dcecba0bbe102fd4" title="Broadcasts to all waiting threads, waking all of them up.">Broadcast()</a> is called. It then locks the mutex again and returns.</p>
<p>Note that even if <a class="el" href="classwx_condition.html#a9fa920a093abdadb19f40db82fbaedd4" title="Signals the object waking up at most one thread.">Signal()</a> had been called before <a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">Wait()</a> without waking up any thread, the thread would still wait for another one and so it is important to ensure that the condition will be signalled after <a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">Wait()</a> or the thread may sleep forever.</p>
<dl class="section return"><dt>Returns</dt><dd>Returns wxCOND_NO_ERROR on success, another value if an error occurred.</dd></dl>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_condition.html#a368e40158c732759fad60d46d292bd2d" title="Waits until the condition is signalled or the timeout has elapsed.">WaitTimeout()</a> </dd></dl>
</div>
</div>
<a class="anchor" id="af7379efa6047603779717ec8fd4c95c9"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<typename Functor > </div>
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> wxCondition::Wait </td>
<td>(</td>
<td class="paramtype">const Functor & </td>
<td class="paramname"><em>predicate</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Waits until the condition is signalled and the associated condition true. </p>
<p>This is a convenience overload that may be used to ignore spurious awakenings while waiting for a specific condition to become true.</p>
<p>Equivalent to </p>
<div class="fragment"><div class="line"><span class="keywordflow">while</span> ( !predicate() )</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e" title="See wxCondition.">wxCondError</a> e = <a class="code" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">Wait</a>();</div>
<div class="line"> <span class="keywordflow">if</span> ( e != <a class="code" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81ea3f408e6093bb067917fb31ad567ad8e5">wxCOND_NO_ERROR</a> )</div>
<div class="line"> <span class="keywordflow">return</span> e;</div>
<div class="line">}</div>
<div class="line"><span class="keywordflow">return</span> <a class="code" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81ea3f408e6093bb067917fb31ad567ad8e5">wxCOND_NO_ERROR</a>;</div>
</div><!-- fragment --><p>The predicate would typically be a C++11 lambda: </p>
<div class="fragment"><div class="line">condvar.Wait([]{<span class="keywordflow">return</span> value == 1;});</div>
</div><!-- fragment --><dl class="section since"><dt>Since</dt><dd>3.0 </dd></dl>
</div>
</div>
<a class="anchor" id="a368e40158c732759fad60d46d292bd2d"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#af963862ae0e1bd5cafe4039dccbbd81e">wxCondError</a> wxCondition::WaitTimeout </td>
<td>(</td>
<td class="paramtype">unsigned long </td>
<td class="paramname"><em>milliseconds</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Waits until the condition is signalled or the timeout has elapsed. </p>
<p>This method is identical to <a class="el" href="classwx_condition.html#ad42af860d727aad40cf366eaab9da48d" title="Waits until the condition is signalled.">Wait()</a> except that it returns, with the return code of <code>wxCOND_TIMEOUT</code> as soon as the given timeout expires.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">milliseconds</td><td>Timeout in milliseconds</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns wxCOND_NO_ERROR if the condition was signalled, wxCOND_TIMEOUT if the timeout elapsed before this happened or another error code from wxCondError enum. </dd></dl>
</div>
</div>
</div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:46:45 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>
|