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
|
<!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: wxSemaphore 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.1</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_semaphore-members.html">List of all members</a> </div>
<div class="headertitle">
<div class="title">wxSemaphore 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_semaphore.html" title="wxSemaphore is a counter limiting the number of threads concurrently accessing a shared resource...">wxSemaphore</a> is a counter limiting the number of threads concurrently accessing a shared resource. </p>
<p>This counter is always between 0 and the maximum value specified during the semaphore creation. When the counter is strictly greater than 0, a call to <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">wxSemaphore::Wait()</a> returns immediately and decrements the counter. As soon as it reaches 0, any subsequent calls to <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">wxSemaphore::Wait</a> block and only return when the semaphore counter becomes strictly positive again as the result of calling <a class="el" href="classwx_semaphore.html#af258c7e7a626fec8a9fc3ff718c960d6" title="Increments the semaphore count and signals one of the waiting threads in an atomic way...">wxSemaphore::Post</a> which increments the counter.</p>
<p>In general, semaphores are useful to restrict access to a shared resource which can only be accessed by some fixed number of clients at the same time. For example, when modeling a hotel reservation system a semaphore with the counter equal to the total number of available rooms could be created. Each time a room is reserved, the semaphore should be acquired by calling <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">wxSemaphore::Wait</a> and each time a room is freed it should be released by calling <a class="el" href="classwx_semaphore.html#af258c7e7a626fec8a9fc3ff718c960d6" title="Increments the semaphore count and signals one of the waiting threads in an atomic way...">wxSemaphore::Post</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> </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:ac3cd6a6d45363c878f366a128294e22c"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_semaphore.html#ac3cd6a6d45363c878f366a128294e22c">wxSemaphore</a> (int initialcount=0, int maxcount=0)</td></tr>
<tr class="memdesc:ac3cd6a6d45363c878f366a128294e22c"><td class="mdescLeft"> </td><td class="mdescRight">Specifying a <em>maxcount</em> of 0 actually makes <a class="el" href="classwx_semaphore.html" title="wxSemaphore is a counter limiting the number of threads concurrently accessing a shared resource...">wxSemaphore</a> behave as if there is no upper limit. <a href="#ac3cd6a6d45363c878f366a128294e22c"></a><br/></td></tr>
<tr class="separator:ac3cd6a6d45363c878f366a128294e22c"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a6192d18717c270bed9ec3a7e7842ef3f"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_semaphore.html#a6192d18717c270bed9ec3a7e7842ef3f">~wxSemaphore</a> ()</td></tr>
<tr class="memdesc:a6192d18717c270bed9ec3a7e7842ef3f"><td class="mdescLeft"> </td><td class="mdescRight">Destructor is not virtual, don't use this class polymorphically. <a href="#a6192d18717c270bed9ec3a7e7842ef3f"></a><br/></td></tr>
<tr class="separator:a6192d18717c270bed9ec3a7e7842ef3f"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:af258c7e7a626fec8a9fc3ff718c960d6"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_semaphore.html#af258c7e7a626fec8a9fc3ff718c960d6">Post</a> ()</td></tr>
<tr class="memdesc:af258c7e7a626fec8a9fc3ff718c960d6"><td class="mdescLeft"> </td><td class="mdescRight">Increments the semaphore count and signals one of the waiting threads in an atomic way. <a href="#af258c7e7a626fec8a9fc3ff718c960d6"></a><br/></td></tr>
<tr class="separator:af258c7e7a626fec8a9fc3ff718c960d6"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a578840a5c04cea87b0121c8e43d480a2"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_semaphore.html#a578840a5c04cea87b0121c8e43d480a2">TryWait</a> ()</td></tr>
<tr class="memdesc:a578840a5c04cea87b0121c8e43d480a2"><td class="mdescLeft"> </td><td class="mdescRight">Same as <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">Wait()</a>, but returns immediately. <a href="#a578840a5c04cea87b0121c8e43d480a2"></a><br/></td></tr>
<tr class="separator:a578840a5c04cea87b0121c8e43d480a2"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a4a54b5fbb2b80b7ca3b8da55e8fa790c"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c">Wait</a> ()</td></tr>
<tr class="memdesc:a4a54b5fbb2b80b7ca3b8da55e8fa790c"><td class="mdescLeft"> </td><td class="mdescRight">Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and return. <a href="#a4a54b5fbb2b80b7ca3b8da55e8fa790c"></a><br/></td></tr>
<tr class="separator:a4a54b5fbb2b80b7ca3b8da55e8fa790c"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a4bef53c549148e807fbf729129ba7572"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_semaphore.html#a4bef53c549148e807fbf729129ba7572">WaitTimeout</a> (unsigned long timeout_millis)</td></tr>
<tr class="memdesc:a4bef53c549148e807fbf729129ba7572"><td class="mdescLeft"> </td><td class="mdescRight">Same as <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">Wait()</a>, but with a timeout limit. <a href="#a4bef53c549148e807fbf729129ba7572"></a><br/></td></tr>
<tr class="separator:a4bef53c549148e807fbf729129ba7572"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a class="anchor" id="ac3cd6a6d45363c878f366a128294e22c"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">wxSemaphore::wxSemaphore </td>
<td>(</td>
<td class="paramtype">int </td>
<td class="paramname"><em>initialcount</em> = <code>0</code>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int </td>
<td class="paramname"><em>maxcount</em> = <code>0</code> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Specifying a <em>maxcount</em> of 0 actually makes <a class="el" href="classwx_semaphore.html" title="wxSemaphore is a counter limiting the number of threads concurrently accessing a shared resource...">wxSemaphore</a> behave as if there is no upper limit. </p>
<p>If <em>maxcount</em> is 1, the semaphore behaves almost as a mutex (but unlike a mutex it can be released by a thread different from the one which acquired it).</p>
<p><em>initialcount</em> is the initial value of the semaphore which must be between 0 and <em>maxcount</em> (if it is not set to 0). </p>
</div>
</div>
<a class="anchor" id="a6192d18717c270bed9ec3a7e7842ef3f"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">wxSemaphore::~wxSemaphore </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Destructor is not virtual, don't use this class polymorphically. </p>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="af258c7e7a626fec8a9fc3ff718c960d6"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> wxSemaphore::Post </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Increments the semaphore count and signals one of the waiting threads in an atomic way. </p>
<p>Returns <em>wxSEMA_OVERFLOW</em> if the count would increase the counter past the maximum.</p>
<dl class="section return"><dt>Returns</dt><dd>One of:<ul>
<li>wxSEMA_NO_ERROR: There was no error.</li>
<li>wxSEMA_INVALID : Semaphore hasn't been initialized successfully.</li>
<li>wxSEMA_OVERFLOW: <a class="el" href="classwx_semaphore.html#af258c7e7a626fec8a9fc3ff718c960d6" title="Increments the semaphore count and signals one of the waiting threads in an atomic way...">Post()</a> would increase counter past the max.</li>
<li>wxSEMA_MISC_ERROR: Miscellaneous error. </li>
</ul>
</dd></dl>
</div>
</div>
<a class="anchor" id="a578840a5c04cea87b0121c8e43d480a2"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> wxSemaphore::TryWait </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Same as <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">Wait()</a>, but returns immediately. </p>
<dl class="section return"><dt>Returns</dt><dd>One of:<ul>
<li>wxSEMA_NO_ERROR: There was no error.</li>
<li>wxSEMA_INVALID: Semaphore hasn't been initialized successfully.</li>
<li>wxSEMA_BUSY: Returned by <a class="el" href="classwx_semaphore.html#a578840a5c04cea87b0121c8e43d480a2" title="Same as Wait(), but returns immediately.">TryWait()</a> if <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">Wait()</a> would block, i.e. the count is zero.</li>
<li>wxSEMA_MISC_ERROR: Miscellaneous error. </li>
</ul>
</dd></dl>
</div>
</div>
<a class="anchor" id="a4a54b5fbb2b80b7ca3b8da55e8fa790c"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> wxSemaphore::Wait </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and return. </p>
<dl class="section return"><dt>Returns</dt><dd>One of:<ul>
<li>wxSEMA_NO_ERROR: There was no error.</li>
<li>wxSEMA_INVALID: Semaphore hasn't been initialized successfully.</li>
<li>wxSEMA_MISC_ERROR: Miscellaneous error. </li>
</ul>
</dd></dl>
</div>
</div>
<a class="anchor" id="a4bef53c549148e807fbf729129ba7572"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#a47100c8fbaa57b192696bec84197398e">wxSemaError</a> wxSemaphore::WaitTimeout </td>
<td>(</td>
<td class="paramtype">unsigned long </td>
<td class="paramname"><em>timeout_millis</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Same as <a class="el" href="classwx_semaphore.html#a4a54b5fbb2b80b7ca3b8da55e8fa790c" title="Wait indefinitely until the semaphore count becomes strictly positive and then decrement it and retur...">Wait()</a>, but with a timeout limit. </p>
<dl class="section return"><dt>Returns</dt><dd>One of:<ul>
<li>wxSEMA_NO_ERROR: There was no error.</li>
<li>wxSEMA_INVALID: Semaphore hasn't been initialized successfully.</li>
<li>wxSEMA_TIMEOUT: Timeout occurred without receiving semaphore.</li>
<li>wxSEMA_MISC_ERROR: Miscellaneous error. </li>
</ul>
</dd></dl>
</div>
</div>
</div><!-- contents -->
<address class="footer">
<small>
Generated on Tue Sep 9 2014 15:03:29 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>
|