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
|
<!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: Threads</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><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#define-members">Macros</a> |
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">Threads</div> </div>
<div class="ingroups"><a class="el" href="group__group__funcmacro.html">Functions and Macros by Category</a></div></div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>The functions and macros here mainly exist to make it possible to write code which may be compiled in multi thread build (wxUSE_THREADS = 1) as well as in single thread configuration (wxUSE_THREADS = 0). </p>
<p>For example, a static variable must be protected against simultaneous access by multiple threads in the former configuration but in the latter the extra overhead of using the critical section is not needed. To solve this problem, the <a class="el" href="group__group__funcmacro__thread.html#ga3b0ab821a03aeecc1a7ddfcecb581355" title="This macro combines wxCRIT_SECT_DECLARE() and wxCRIT_SECT_LOCKER(): it creates a static critical sect...">wxCRITICAL_SECTION()</a> macro may be used to create and use the critical section only when needed.</p>
<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>, <a class="el" href="overview_thread.html">Multithreading Overview</a></dd></dl>
<p>Related class group: <a class="el" href="group__group__class__threading.html">Threading</a> </p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ga79ee915c6353e705958843a57a5148e2"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#ga79ee915c6353e705958843a57a5148e2">wxCRIT_SECT_DECLARE</a>(cs)</td></tr>
<tr class="memdesc:ga79ee915c6353e705958843a57a5148e2"><td class="mdescLeft"> </td><td class="mdescRight">This macro declares a (static) critical section object named <em>cs</em> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. <a href="#ga79ee915c6353e705958843a57a5148e2"></a><br/></td></tr>
<tr class="separator:ga79ee915c6353e705958843a57a5148e2"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gaa9f05a4361ea095939f90512ee52a831"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#gaa9f05a4361ea095939f90512ee52a831">wxCRIT_SECT_DECLARE_MEMBER</a>(cs)</td></tr>
<tr class="memdesc:gaa9f05a4361ea095939f90512ee52a831"><td class="mdescLeft"> </td><td class="mdescRight">This macro declares a critical section object named <em>cs</em> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. <a href="#gaa9f05a4361ea095939f90512ee52a831"></a><br/></td></tr>
<tr class="separator:gaa9f05a4361ea095939f90512ee52a831"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gae589848294c2cf63ad6895c4344755fe"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#gae589848294c2cf63ad6895c4344755fe">wxCRIT_SECT_LOCKER</a>(name, cs)</td></tr>
<tr class="memdesc:gae589848294c2cf63ad6895c4344755fe"><td class="mdescLeft"> </td><td class="mdescRight">This macro creates a <a class="el" href="classwx_critical_section_locker.html" title="This is a small helper class to be used with wxCriticalSection objects.">wxCriticalSectionLocker</a> named <em>name</em> and associated with the critical section <em>cs</em> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. <a href="#gae589848294c2cf63ad6895c4344755fe"></a><br/></td></tr>
<tr class="separator:gae589848294c2cf63ad6895c4344755fe"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga3b0ab821a03aeecc1a7ddfcecb581355"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#ga3b0ab821a03aeecc1a7ddfcecb581355">wxCRITICAL_SECTION</a>(name)</td></tr>
<tr class="memdesc:ga3b0ab821a03aeecc1a7ddfcecb581355"><td class="mdescLeft"> </td><td class="mdescRight">This macro combines <a class="el" href="group__group__funcmacro__thread.html#ga79ee915c6353e705958843a57a5148e2" title="This macro declares a (static) critical section object named cs if wxUSE_THREADS is 1 and does nothin...">wxCRIT_SECT_DECLARE()</a> and <a class="el" href="group__group__funcmacro__thread.html#gae589848294c2cf63ad6895c4344755fe" title="This macro creates a wxCriticalSectionLocker named name and associated with the critical section cs i...">wxCRIT_SECT_LOCKER()</a>: it creates a static critical section object and also the lock object associated with it. <a href="#ga3b0ab821a03aeecc1a7ddfcecb581355"></a><br/></td></tr>
<tr class="separator:ga3b0ab821a03aeecc1a7ddfcecb581355"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gab5a243025a42da8c351a2df8519f4208"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#gab5a243025a42da8c351a2df8519f4208">wxLEAVE_CRIT_SECT</a>(critical_section)</td></tr>
<tr class="memdesc:gab5a243025a42da8c351a2df8519f4208"><td class="mdescLeft"> </td><td class="mdescRight">This macro is equivalent to <a class="el" href="classwx_critical_section.html#a9710ab7240b29a653fd9233c12aadba6">critical_section.Leave()</a> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. <a href="#gab5a243025a42da8c351a2df8519f4208"></a><br/></td></tr>
<tr class="separator:gab5a243025a42da8c351a2df8519f4208"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga53ce988bc3201b82b77d4779610be608"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#ga53ce988bc3201b82b77d4779610be608">wxENTER_CRIT_SECT</a>(critical_section)</td></tr>
<tr class="memdesc:ga53ce988bc3201b82b77d4779610be608"><td class="mdescLeft"> </td><td class="mdescRight">This macro is equivalent to <a class="el" href="classwx_critical_section.html#afa80c7cb306d72884ebcc4e60ea61d39">critical_section.Enter()</a> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. <a href="#ga53ce988bc3201b82b77d4779610be608"></a><br/></td></tr>
<tr class="separator:ga53ce988bc3201b82b77d4779610be608"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga11517a2eeeb6367d9e0d705fa29dd97e"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#ga11517a2eeeb6367d9e0d705fa29dd97e">wxIsMainThread</a> ()</td></tr>
<tr class="memdesc:ga11517a2eeeb6367d9e0d705fa29dd97e"><td class="mdescLeft"> </td><td class="mdescRight">Returns <span class="literal">true</span> if this thread is the main one. <a href="#ga11517a2eeeb6367d9e0d705fa29dd97e"></a><br/></td></tr>
<tr class="separator:ga11517a2eeeb6367d9e0d705fa29dd97e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga6671c1599fd4ccf6a7c7bb90b2304709"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#ga6671c1599fd4ccf6a7c7bb90b2304709">wxMutexGuiEnter</a> ()</td></tr>
<tr class="memdesc:ga6671c1599fd4ccf6a7c7bb90b2304709"><td class="mdescLeft"> </td><td class="mdescRight">This function must be called when any thread other than the main GUI thread wants to get access to the GUI library. <a href="#ga6671c1599fd4ccf6a7c7bb90b2304709"></a><br/></td></tr>
<tr class="separator:ga6671c1599fd4ccf6a7c7bb90b2304709"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gaddfdb2956953480a379d998ea7ced5b5"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__funcmacro__thread.html#gaddfdb2956953480a379d998ea7ced5b5">wxMutexGuiLeave</a> ()</td></tr>
<tr class="memdesc:gaddfdb2956953480a379d998ea7ced5b5"><td class="mdescLeft"> </td><td class="mdescRight">This function is only defined on platforms which support preemptive threads. <a href="#gaddfdb2956953480a379d998ea7ced5b5"></a><br/></td></tr>
<tr class="separator:gaddfdb2956953480a379d998ea7ced5b5"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<h2 class="groupheader">Macro Definition Documentation</h2>
<a class="anchor" id="ga79ee915c6353e705958843a57a5148e2"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define wxCRIT_SECT_DECLARE</td>
<td>(</td>
<td class="paramtype"> </td>
<td class="paramname">cs</td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This macro declares a (static) critical section object named <em>cs</em> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. </p>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<a class="anchor" id="gaa9f05a4361ea095939f90512ee52a831"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define wxCRIT_SECT_DECLARE_MEMBER</td>
<td>(</td>
<td class="paramtype"> </td>
<td class="paramname">cs</td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This macro declares a critical section object named <em>cs</em> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. </p>
<p>As it doesn't include the <code>static</code> keyword (unlike <a class="el" href="group__group__funcmacro__thread.html#ga79ee915c6353e705958843a57a5148e2" title="This macro declares a (static) critical section object named cs if wxUSE_THREADS is 1 and does nothin...">wxCRIT_SECT_DECLARE()</a>), it can be used to declare a class or struct member which explains its name.</p>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<a class="anchor" id="gae589848294c2cf63ad6895c4344755fe"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define wxCRIT_SECT_LOCKER</td>
<td>(</td>
<td class="paramtype"> </td>
<td class="paramname">name, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"> </td>
<td class="paramname">cs </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This macro creates a <a class="el" href="classwx_critical_section_locker.html" title="This is a small helper class to be used with wxCriticalSection objects.">wxCriticalSectionLocker</a> named <em>name</em> and associated with the critical section <em>cs</em> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. </p>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<a class="anchor" id="ga3b0ab821a03aeecc1a7ddfcecb581355"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define wxCRITICAL_SECTION</td>
<td>(</td>
<td class="paramtype"> </td>
<td class="paramname">name</td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This macro combines <a class="el" href="group__group__funcmacro__thread.html#ga79ee915c6353e705958843a57a5148e2" title="This macro declares a (static) critical section object named cs if wxUSE_THREADS is 1 and does nothin...">wxCRIT_SECT_DECLARE()</a> and <a class="el" href="group__group__funcmacro__thread.html#gae589848294c2cf63ad6895c4344755fe" title="This macro creates a wxCriticalSectionLocker named name and associated with the critical section cs i...">wxCRIT_SECT_LOCKER()</a>: it creates a static critical section object and also the lock object associated with it. </p>
<p>Because of this, it can be only used inside a function, not at global scope. For example:</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> IncCount()</div>
<div class="line">{</div>
<div class="line"> <span class="keyword">static</span> <span class="keywordtype">int</span> s_counter = 0;</div>
<div class="line"></div>
<div class="line"> <a class="code" href="group__group__funcmacro__thread.html#ga3b0ab821a03aeecc1a7ddfcecb581355" title="This macro combines wxCRIT_SECT_DECLARE() and wxCRIT_SECT_LOCKER(): it creates a static critical sect...">wxCRITICAL_SECTION</a>(counter);</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> ++s_counter;</div>
<div class="line">}</div>
</div><!-- fragment --><p>Note that this example assumes that the function is called the first time from the main thread so that the critical section object is initialized correctly by the time other threads start calling it, if this is not the case this approach can <b>not</b> be used and the critical section must be made a global instead.</p>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<a class="anchor" id="ga53ce988bc3201b82b77d4779610be608"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define wxENTER_CRIT_SECT</td>
<td>(</td>
<td class="paramtype"> </td>
<td class="paramname">critical_section</td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This macro is equivalent to <a class="el" href="classwx_critical_section.html#afa80c7cb306d72884ebcc4e60ea61d39">critical_section.Enter()</a> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. </p>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<a class="anchor" id="gab5a243025a42da8c351a2df8519f4208"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define wxLEAVE_CRIT_SECT</td>
<td>(</td>
<td class="paramtype"> </td>
<td class="paramname">critical_section</td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This macro is equivalent to <a class="el" href="classwx_critical_section.html#a9710ab7240b29a653fd9233c12aadba6">critical_section.Leave()</a> if <code>wxUSE_THREADS</code> is 1 and does nothing if it is 0. </p>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="ga11517a2eeeb6367d9e0d705fa29dd97e"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool wxIsMainThread </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns <span class="literal">true</span> if this thread is the main one. </p>
<p>Always returns <span class="literal">true</span> if <code>wxUSE_THREADS</code> is 0.</p>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<a class="anchor" id="ga6671c1599fd4ccf6a7c7bb90b2304709"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void wxMutexGuiEnter </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This function must be called when any thread other than the main GUI thread wants to get access to the GUI library. </p>
<p>This function will block the execution of the calling thread until the main thread (or any other thread holding the main GUI lock) leaves the GUI library and no other thread will enter the GUI library until the calling thread calls <a class="el" href="group__group__funcmacro__thread.html#gaddfdb2956953480a379d998ea7ced5b5" title="This function is only defined on platforms which support preemptive threads.">wxMutexGuiLeave()</a>.</p>
<p>Typically, these functions are used like this:</p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> MyThread::Foo(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// before doing any GUI calls we must ensure that</span></div>
<div class="line"> <span class="comment">// this thread is the only one doing it!</span></div>
<div class="line"></div>
<div class="line"> <a class="code" href="group__group__funcmacro__thread.html#ga6671c1599fd4ccf6a7c7bb90b2304709" title="This function must be called when any thread other than the main GUI thread wants to get access to th...">wxMutexGuiEnter</a>();</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Call GUI here:</span></div>
<div class="line"> my_window->DrawSomething();</div>
<div class="line"></div>
<div class="line"> <a class="code" href="group__group__funcmacro__thread.html#gaddfdb2956953480a379d998ea7ced5b5" title="This function is only defined on platforms which support preemptive threads.">wxMutexGuiLeave</a>();</div>
<div class="line">}</div>
</div><!-- fragment --><p>This function is only defined on platforms which support preemptive threads and only works under some ports (wxMSW currently).</p>
<dl class="section note"><dt>Note</dt><dd>Under GTK, no creation of top-level windows is allowed in any thread but the main one.</dd></dl>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
<a class="anchor" id="gaddfdb2956953480a379d998ea7ced5b5"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void wxMutexGuiLeave </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This function is only defined on platforms which support preemptive threads. </p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="group__group__funcmacro__thread.html#ga6671c1599fd4ccf6a7c7bb90b2304709" title="This function must be called when any thread other than the main GUI thread wants to get access to th...">wxMutexGuiEnter()</a></dd></dl>
<p>Include file: </p>
<pre class="fragment">#include <wx/thread.h> </pre>
</div>
</div>
</div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:46:43 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>
|