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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
|
<!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: wxThreadHelper 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_thread_helper-members.html">List of all members</a> </div>
<div class="headertitle">
<div class="title">wxThreadHelper Class Reference<span class="mlabels"><span class="mlabel">abstract</span></span><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>The <a class="el" href="classwx_thread_helper.html" title="The wxThreadHelper class is a mix-in class that manages a single background thread, either detached or joinable (see wxThread for the differences).">wxThreadHelper</a> class is a mix-in class that manages a single background thread, either detached or joinable (see <a class="el" href="classwx_thread.html" title="A thread is basically a path of execution through a program.">wxThread</a> for the differences). </p>
<p>By deriving from <a class="el" href="classwx_thread_helper.html" title="The wxThreadHelper class is a mix-in class that manages a single background thread, either detached or joinable (see wxThread for the differences).">wxThreadHelper</a>, a class can implement the thread code in its own <a class="el" href="classwx_thread_helper.html#a7f3e0f028fb1b295bc61064ad4d4bc1b" title="This is the entry point of the thread.">wxThreadHelper::Entry()</a> method and easily share data and synchronization objects between the main thread and the worker thread.</p>
<p>Doing this prevents the awkward passing of pointers that is needed when the original object in the main thread needs to synchronize with its worker thread in its own <a class="el" href="classwx_thread.html" title="A thread is basically a path of execution through a program.">wxThread</a> derived object.</p>
<p>For example, <a class="el" href="classwx_frame.html" title="A frame is a window whose size and position can (usually) be changed by the user.">wxFrame</a> may need to make some calculations in a background thread and then display the results of those calculations in the main window.</p>
<p>Ordinarily, a <a class="el" href="classwx_thread.html" title="A thread is basically a path of execution through a program.">wxThread</a> derived object would be created with the calculation code implemented in <a class="el" href="classwx_thread.html#af50fa7d3ac55002e367e79989b9cbc5d" title="This is the entry point of the thread.">wxThread::Entry</a>. To access the inputs to the calculation, the frame object would often need to pass a pointer to itself to the thread object. Similarly, the frame object would hold a pointer to the thread object.</p>
<p>Shared data and synchronization objects could be stored in either object though the object without the data would have to access the data through a pointer. However with <a class="el" href="classwx_thread_helper.html" title="The wxThreadHelper class is a mix-in class that manages a single background thread, either detached or joinable (see wxThread for the differences).">wxThreadHelper</a> the frame object and the thread object are treated as the same object. Shared data and synchronization variables are stored in the single object, eliminating a layer of indirection and the associated pointers.</p>
<p>Example: </p>
<div class="fragment"><div class="line"><a class="code" href="group__group__funcmacro__events.html#ga767b12d37f7370bc5f6b3d62340f3ef8" title="Declares a custom event type.">wxDECLARE_EVENT</a>(myEVT_THREAD_UPDATE, <a class="code" href="classwx_thread_event.html" title="This class adds some simple functionality to wxEvent to facilitate inter-thread communication.">wxThreadEvent</a>);</div>
<div class="line"></div>
<div class="line"><span class="keyword">class </span>MyFrame : <span class="keyword">public</span> <a class="code" href="classwx_frame.html" title="A frame is a window whose size and position can (usually) be changed by the user.">wxFrame</a>, <span class="keyword">public</span> <a class="code" href="classwx_thread_helper.html" title="The wxThreadHelper class is a mix-in class that manages a single background thread, either detached or joinable (see wxThread for the differences).">wxThreadHelper</a></div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> MyFrame(...) { ... }</div>
<div class="line"> ~MyFrame()</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// it's better to do any thread cleanup in the OnClose()</span></div>
<div class="line"> <span class="comment">// event handler, rather than in the destructor.</span></div>
<div class="line"> <span class="comment">// This is because the event loop for a top-level window is not</span></div>
<div class="line"> <span class="comment">// active anymore when its destructor is called and if the thread</span></div>
<div class="line"> <span class="comment">// sends events when ending, they won't be processed unless</span></div>
<div class="line"> <span class="comment">// you ended the thread from OnClose.</span></div>
<div class="line"> <span class="comment">// See @ref overview_windowdeletion for more info.</span></div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> ...</div>
<div class="line"> <span class="keywordtype">void</span> DoStartALongTask();</div>
<div class="line"> <span class="keywordtype">void</span> OnThreadUpdate(<a class="code" href="classwx_thread_event.html" title="This class adds some simple functionality to wxEvent to facilitate inter-thread communication.">wxThreadEvent</a>& evt);</div>
<div class="line"> <span class="keywordtype">void</span> OnClose(<a class="code" href="classwx_close_event.html" title="This event class contains information about window and session close events.">wxCloseEvent</a>& evt);</div>
<div class="line"> ...</div>
<div class="line"></div>
<div class="line">protected:</div>
<div class="line"> <span class="keyword">virtual</span> <a class="code" href="classwx_thread.html#ade9497fa072fe19481086e6486dcc028" title="The return type for the thread functions.">wxThread::ExitCode</a> <a class="code" href="classwx_thread_helper.html#a7f3e0f028fb1b295bc61064ad4d4bc1b" title="This is the entry point of the thread.">Entry</a>();</div>
<div class="line"></div>
<div class="line"> <span class="comment">// the output data of the Entry() routine:</span></div>
<div class="line"> <span class="keywordtype">char</span> m_data[1024];</div>
<div class="line"> <a class="code" href="classwx_critical_section.html" title="A critical section object is used for exactly the same purpose as a wxMutex.">wxCriticalSection</a> m_dataCS; <span class="comment">// protects field above</span></div>
<div class="line"></div>
<div class="line"> <a class="code" href="group__group__funcmacro__events.html#gab6eca03fad44ec10b75d3cb82e9219e3" title="Use this macro inside a class declaration to declare a static event table for that class...">wxDECLARE_EVENT_TABLE</a>();</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"><a class="code" href="group__group__funcmacro__events.html#ga09ec1d095bee3085c1cb31459b46bc00" title="Define a new event type associated with the specified event class.">wxDEFINE_EVENT</a>(myEVT_THREAD_UPDATE, <a class="code" href="classwx_thread_event.html" title="This class adds some simple functionality to wxEvent to facilitate inter-thread communication.">wxThreadEvent</a>)</div>
<div class="line"><a class="code" href="group__group__funcmacro__events.html#ga736930efaab4d7e445e9e8e520c7b74d" title="Use this macro in a source file to start listing static event handlers for a specific class...">wxBEGIN_EVENT_TABLE</a>(MyFrame, <a class="code" href="classwx_frame.html" title="A frame is a window whose size and position can (usually) be changed by the user.">wxFrame</a>)</div>
<div class="line"> EVT_THREAD(wxID_ANY, myEVT_THREAD_UPDATE, MyFrame::OnThreadUpdate)</div>
<div class="line"> EVT_CLOSE(MyFrame::OnClose)</div>
<div class="line"><a class="code" href="group__group__funcmacro__events.html#ga383fad2a46e1d6c220fbe03ecfbc9c17" title="Use this macro in a source file to end listing static event handlers for a specific class...">wxEND_EVENT_TABLE</a>()</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> MyFrame::DoStartALongTask()</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// we want to start a long task, but we don't want our GUI to block</span></div>
<div class="line"> <span class="comment">// while it's executed, so we use a thread to do it.</span></div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="classwx_thread_helper.html#a3682b1b5a08741335aa8acc7feb0ece5" title="Creates a new thread of the given kind.">CreateThread</a>(<a class="code" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0ab5246cc8dc6eeb20bc69e4790e7b00a4" title="Joinable thread.">wxTHREAD_JOINABLE</a>) != <a class="code" href="interface_2wx_2thread_8h.html#a9e4ba0577f752fee0ba2133035f75ac2ad1525fe128b4989cb43a7e8112ac1b13" title="No error.">wxTHREAD_NO_ERROR</a>)</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="group__group__funcmacro__log.html#ga0dd3c633f990f794e76065c9a7af4c87" title="The functions to use for error messages, i.e.">wxLogError</a>(<span class="stringliteral">"Could not create the worker thread!"</span>);</div>
<div class="line"> <span class="keywordflow">return</span>;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">// go!</span></div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="classwx_thread_helper.html#ac61fe16deda566773cdc7d4d38709370" title="This is a public function that returns the wxThread object associated with the thread.">GetThread</a>()->Run() != <a class="code" href="interface_2wx_2thread_8h.html#a9e4ba0577f752fee0ba2133035f75ac2ad1525fe128b4989cb43a7e8112ac1b13" title="No error.">wxTHREAD_NO_ERROR</a>)</div>
<div class="line"> {</div>
<div class="line"> <a class="code" href="group__group__funcmacro__log.html#ga0dd3c633f990f794e76065c9a7af4c87" title="The functions to use for error messages, i.e.">wxLogError</a>(<span class="stringliteral">"Could not run the worker thread!"</span>);</div>
<div class="line"> <span class="keywordflow">return</span>;</div>
<div class="line"> }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><a class="code" href="classwx_thread.html#ade9497fa072fe19481086e6486dcc028" title="The return type for the thread functions.">wxThread::ExitCode</a> MyFrame::Entry()</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// IMPORTANT:</span></div>
<div class="line"> <span class="comment">// this function gets executed in the secondary thread context!</span></div>
<div class="line"></div>
<div class="line"> <span class="keywordtype">int</span> offset = 0;</div>
<div class="line"></div>
<div class="line"> <span class="comment">// here we do our long task, periodically calling TestDestroy():</span></div>
<div class="line"> <span class="keywordflow">while</span> (!<a class="code" href="classwx_thread_helper.html#ac61fe16deda566773cdc7d4d38709370" title="This is a public function that returns the wxThread object associated with the thread.">GetThread</a>()->TestDestroy())</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// since this Entry() is implemented in MyFrame context we don't</span></div>
<div class="line"> <span class="comment">// need any pointer to access the m_data, m_processedData, m_dataCS</span></div>
<div class="line"> <span class="comment">// variables... very nice!</span></div>
<div class="line"></div>
<div class="line"> <span class="comment">// this is an example of the generic structure of a download thread:</span></div>
<div class="line"> <span class="keywordtype">char</span> buffer[1024];</div>
<div class="line"> download_chunk(buffer, 1024); <span class="comment">// this takes time...</span></div>
<div class="line"></div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// ensure no one reads m_data while we write it</span></div>
<div class="line"> <a class="code" href="classwx_critical_section_locker.html" title="This is a small helper class to be used with wxCriticalSection objects.">wxCriticalSectionLocker</a> lock(m_dataCS);</div>
<div class="line"> memcpy(m_data+offset, buffer, 1024);</div>
<div class="line"> offset += 1024;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"> <span class="comment">// VERY IMPORTANT: do not call any GUI function inside this</span></div>
<div class="line"> <span class="comment">// function; rather use wxQueueEvent():</span></div>
<div class="line"> <a class="code" href="group__group__funcmacro__events.html#gae921d7bd0e52fedbf3f253d2c408bce1" title="Queue an event for processing on the given object.">wxQueueEvent</a>(<span class="keyword">this</span>, <span class="keyword">new</span> <a class="code" href="classwx_thread_event.html" title="This class adds some simple functionality to wxEvent to facilitate inter-thread communication.">wxThreadEvent</a>(wxEVT_COMMAND_MYTHREAD_UPDATE));</div>
<div class="line"> <span class="comment">// we used pointer 'this' assuming it's safe; see OnClose()</span></div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">// TestDestroy() returned true (which means the main thread asked us</span></div>
<div class="line"> <span class="comment">// to terminate as soon as possible) or we ended the long task...</span></div>
<div class="line"> <span class="keywordflow">return</span> (<a class="code" href="classwx_thread.html#ade9497fa072fe19481086e6486dcc028" title="The return type for the thread functions.">wxThread::ExitCode</a>)0;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> MyFrame::OnClose(<a class="code" href="classwx_close_event.html" title="This event class contains information about window and session close events.">wxCloseEvent</a>&)</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// important: before terminating, we _must_ wait for our joinable</span></div>
<div class="line"> <span class="comment">// thread to end, if it's running; in fact it uses variables of this</span></div>
<div class="line"> <span class="comment">// instance and posts events to *this event handler</span></div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="classwx_thread_helper.html#ac61fe16deda566773cdc7d4d38709370" title="This is a public function that returns the wxThread object associated with the thread.">GetThread</a>() && <span class="comment">// DoStartALongTask() may have not been called</span></div>
<div class="line"> <a class="code" href="classwx_thread_helper.html#ac61fe16deda566773cdc7d4d38709370" title="This is a public function that returns the wxThread object associated with the thread.">GetThread</a>()->IsRunning())</div>
<div class="line"> <a class="code" href="classwx_thread_helper.html#ac61fe16deda566773cdc7d4d38709370" title="This is a public function that returns the wxThread object associated with the thread.">GetThread</a>()-><a class="code" href="classwx_thread.html#a62ee778033013d3a4754b71b8cf2902e" title="Waits for a joinable thread to terminate and returns the value the thread returned from Entry() or "(...">Wait</a>();</div>
<div class="line"></div>
<div class="line"> Destroy();</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> MyFrame::OnThreadUpdate(<a class="code" href="classwx_thread_event.html" title="This class adds some simple functionality to wxEvent to facilitate inter-thread communication.">wxThreadEvent</a>& evt)</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// ...do something... e.g. m_pGauge->Pulse();</span></div>
<div class="line"></div>
<div class="line"> <span class="comment">// read some parts of m_data just for fun:</span></div>
<div class="line"> <a class="code" href="classwx_critical_section_locker.html" title="This is a small helper class to be used with wxCriticalSection objects.">wxCriticalSectionLocker</a> lock(m_dataCS);</div>
<div class="line"> wxPrintf(<span class="stringliteral">"%c"</span>, m_data[100]);</div>
<div class="line">}</div>
</div><!-- fragment --><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_thread_event.html" title="This class adds some simple functionality to wxEvent to facilitate inter-thread communication.">wxThreadEvent</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:ace38e9960ed62f8cafdfc8f7008815ae"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#ace38e9960ed62f8cafdfc8f7008815ae">wxThreadHelper</a> (<a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0">wxThreadKind</a> kind=<a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0ab5246cc8dc6eeb20bc69e4790e7b00a4">wxTHREAD_JOINABLE</a>)</td></tr>
<tr class="memdesc:ace38e9960ed62f8cafdfc8f7008815ae"><td class="mdescLeft"> </td><td class="mdescRight">This constructor simply initializes internal member variables and tells <a class="el" href="classwx_thread_helper.html" title="The wxThreadHelper class is a mix-in class that manages a single background thread, either detached or joinable (see wxThread for the differences).">wxThreadHelper</a> which type the thread internally managed should be. <a href="#ace38e9960ed62f8cafdfc8f7008815ae"></a><br/></td></tr>
<tr class="separator:ace38e9960ed62f8cafdfc8f7008815ae"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:affe96946d9bceaba028209f4fd90ddf8"><td class="memItemLeft" align="right" valign="top">virtual </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#affe96946d9bceaba028209f4fd90ddf8">~wxThreadHelper</a> ()</td></tr>
<tr class="memdesc:affe96946d9bceaba028209f4fd90ddf8"><td class="mdescLeft"> </td><td class="mdescRight">The destructor frees the resources associated with the thread, forcing it to terminate (it uses <a class="el" href="classwx_thread.html#a2cbff8b3b0a93ab82f212c02f38a1ef4" title="Immediately terminates the target thread.">wxThread::Kill</a> function). <a href="#affe96946d9bceaba028209f4fd90ddf8"></a><br/></td></tr>
<tr class="separator:affe96946d9bceaba028209f4fd90ddf8"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a7f3e0f028fb1b295bc61064ad4d4bc1b"><td class="memItemLeft" align="right" valign="top">virtual ExitCode </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#a7f3e0f028fb1b295bc61064ad4d4bc1b">Entry</a> ()=0</td></tr>
<tr class="memdesc:a7f3e0f028fb1b295bc61064ad4d4bc1b"><td class="mdescLeft"> </td><td class="mdescRight">This is the entry point of the thread. <a href="#a7f3e0f028fb1b295bc61064ad4d4bc1b"></a><br/></td></tr>
<tr class="separator:a7f3e0f028fb1b295bc61064ad4d4bc1b"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ad6275bdfa1590d13f4890a433ee3e1c2"><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#ad6275bdfa1590d13f4890a433ee3e1c2">OnDelete</a> ()</td></tr>
<tr class="memdesc:ad6275bdfa1590d13f4890a433ee3e1c2"><td class="mdescLeft"> </td><td class="mdescRight">Callback called by Delete() before actually deleting the thread. <a href="#ad6275bdfa1590d13f4890a433ee3e1c2"></a><br/></td></tr>
<tr class="separator:ad6275bdfa1590d13f4890a433ee3e1c2"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:aafc07894e382cbd964c3e9900b2b780b"><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#aafc07894e382cbd964c3e9900b2b780b">OnKill</a> ()</td></tr>
<tr class="memdesc:aafc07894e382cbd964c3e9900b2b780b"><td class="mdescLeft"> </td><td class="mdescRight">Callback called by Kill() before actually killing the thread. <a href="#aafc07894e382cbd964c3e9900b2b780b"></a><br/></td></tr>
<tr class="separator:aafc07894e382cbd964c3e9900b2b780b"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ae9f65014cb9c8ef1d27f22d6259c0fc2"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#a9e4ba0577f752fee0ba2133035f75ac2">wxThreadError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#ae9f65014cb9c8ef1d27f22d6259c0fc2">Create</a> (unsigned int stackSize=0)</td></tr>
<tr class="separator:ae9f65014cb9c8ef1d27f22d6259c0fc2"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a3682b1b5a08741335aa8acc7feb0ece5"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#a9e4ba0577f752fee0ba2133035f75ac2">wxThreadError</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#a3682b1b5a08741335aa8acc7feb0ece5">CreateThread</a> (<a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0">wxThreadKind</a> kind=<a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0ab5246cc8dc6eeb20bc69e4790e7b00a4">wxTHREAD_JOINABLE</a>, unsigned int stackSize=0)</td></tr>
<tr class="memdesc:a3682b1b5a08741335aa8acc7feb0ece5"><td class="mdescLeft"> </td><td class="mdescRight">Creates a new thread of the given <em>kind</em>. <a href="#a3682b1b5a08741335aa8acc7feb0ece5"></a><br/></td></tr>
<tr class="separator:a3682b1b5a08741335aa8acc7feb0ece5"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ac61fe16deda566773cdc7d4d38709370"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classwx_thread.html">wxThread</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#ac61fe16deda566773cdc7d4d38709370">GetThread</a> () const </td></tr>
<tr class="memdesc:ac61fe16deda566773cdc7d4d38709370"><td class="mdescLeft"> </td><td class="mdescRight">This is a public function that returns the <a class="el" href="classwx_thread.html" title="A thread is basically a path of execution through a program.">wxThread</a> object associated with the thread. <a href="#ac61fe16deda566773cdc7d4d38709370"></a><br/></td></tr>
<tr class="separator:ac61fe16deda566773cdc7d4d38709370"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ae84f7a6b2bfc7e890d0dfd296cbc43cd"><td class="memItemLeft" align="right" valign="top"><a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0">wxThreadKind</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_thread_helper.html#ae84f7a6b2bfc7e890d0dfd296cbc43cd">GetThreadKind</a> () const </td></tr>
<tr class="memdesc:ae84f7a6b2bfc7e890d0dfd296cbc43cd"><td class="mdescLeft"> </td><td class="mdescRight">Returns the last type of thread given to the <a class="el" href="classwx_thread_helper.html#a3682b1b5a08741335aa8acc7feb0ece5" title="Creates a new thread of the given kind.">CreateThread()</a> function or to the constructor. <a href="#ae84f7a6b2bfc7e890d0dfd296cbc43cd"></a><br/></td></tr>
<tr class="separator:ae84f7a6b2bfc7e890d0dfd296cbc43cd"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a class="anchor" id="ace38e9960ed62f8cafdfc8f7008815ae"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">wxThreadHelper::wxThreadHelper </td>
<td>(</td>
<td class="paramtype"><a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0">wxThreadKind</a> </td>
<td class="paramname"><em>kind</em> = <code><a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0ab5246cc8dc6eeb20bc69e4790e7b00a4">wxTHREAD_JOINABLE</a></code></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This constructor simply initializes internal member variables and tells <a class="el" href="classwx_thread_helper.html" title="The wxThreadHelper class is a mix-in class that manages a single background thread, either detached or joinable (see wxThread for the differences).">wxThreadHelper</a> which type the thread internally managed should be. </p>
</div>
</div>
<a class="anchor" id="affe96946d9bceaba028209f4fd90ddf8"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">virtual wxThreadHelper::~wxThreadHelper </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>The destructor frees the resources associated with the thread, forcing it to terminate (it uses <a class="el" href="classwx_thread.html#a2cbff8b3b0a93ab82f212c02f38a1ef4" title="Immediately terminates the target thread.">wxThread::Kill</a> function). </p>
<p>Because of the <a class="el" href="classwx_thread.html#a2cbff8b3b0a93ab82f212c02f38a1ef4" title="Immediately terminates the target thread.">wxThread::Kill</a> unsafety, you should always wait (with <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 joinable threads to end or call <a class="el" href="classwx_thread.html#a66796042bf5f3eb33a0ad3db85f686d4" title="Calling Delete() gracefully terminates a detached thread, either when the thread calls TestDestroy() ...">wxThread::Delete</a> on detached threads, instead of relying on this destructor for stopping the thread. </p>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="ae9f65014cb9c8ef1d27f22d6259c0fc2"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#a9e4ba0577f752fee0ba2133035f75ac2">wxThreadError</a> wxThreadHelper::Create </td>
<td>(</td>
<td class="paramtype">unsigned int </td>
<td class="paramname"><em>stackSize</em> = <code>0</code></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="deprecated"><dt><b><a class="el" href="deprecated.html#_deprecated000054">Deprecated:</a></b></dt><dd>Use <a class="el" href="classwx_thread_helper.html#a3682b1b5a08741335aa8acc7feb0ece5" title="Creates a new thread of the given kind.">CreateThread()</a> instead. </dd></dl>
</div>
</div>
<a class="anchor" id="a3682b1b5a08741335aa8acc7feb0ece5"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#a9e4ba0577f752fee0ba2133035f75ac2">wxThreadError</a> wxThreadHelper::CreateThread </td>
<td>(</td>
<td class="paramtype"><a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0">wxThreadKind</a> </td>
<td class="paramname"><em>kind</em> = <code><a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0ab5246cc8dc6eeb20bc69e4790e7b00a4">wxTHREAD_JOINABLE</a></code>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">unsigned int </td>
<td class="paramname"><em>stackSize</em> = <code>0</code> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Creates a new thread of the given <em>kind</em>. </p>
<p>The thread object is created in the suspended state, and you should call <a class="el" href="classwx_thread.html#a5d894750ffaac8fc42ee85aeff8bb4c0">GetThread()->Run()</a> to start running it.</p>
<p>You may optionally specify the stack size to be allocated to it (ignored on platforms that don't support setting it explicitly, e.g. Unix).</p>
<dl class="section return"><dt>Returns</dt><dd>One of the <a class="el" href="interface_2wx_2thread_8h.html#a9e4ba0577f752fee0ba2133035f75ac2" title="The possible thread errors.">wxThreadError</a> enum values. </dd></dl>
</div>
</div>
<a class="anchor" id="a7f3e0f028fb1b295bc61064ad4d4bc1b"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">virtual ExitCode wxThreadHelper::Entry </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>This is the entry point of the thread. </p>
<p>This function is pure virtual and must be implemented by any derived class. The thread execution will start here.</p>
<p>You'll typically want your <a class="el" href="classwx_thread_helper.html#a7f3e0f028fb1b295bc61064ad4d4bc1b" title="This is the entry point of the thread.">Entry()</a> to look like: </p>
<div class="fragment"><div class="line"><a class="code" href="classwx_thread.html#ade9497fa072fe19481086e6486dcc028" title="The return type for the thread functions.">wxThread::ExitCode</a> <a class="code" href="classwx_thread_helper.html#a7f3e0f028fb1b295bc61064ad4d4bc1b" title="This is the entry point of the thread.">Entry</a>()</div>
<div class="line">{</div>
<div class="line"> <span class="keywordflow">while</span> (!<a class="code" href="classwx_thread_helper.html#ac61fe16deda566773cdc7d4d38709370" title="This is a public function that returns the wxThread object associated with the thread.">GetThread</a>()->TestDestroy())</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// ... do some work ...</span></div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">if</span> (IsWorkCompleted)</div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">if</span> (HappenedStoppingError)</div>
<div class="line"> <span class="keywordflow">return</span> (<a class="code" href="classwx_thread.html#ade9497fa072fe19481086e6486dcc028" title="The return type for the thread functions.">wxThread::ExitCode</a>)1; <span class="comment">// failure</span></div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> (<a class="code" href="classwx_thread.html#ade9497fa072fe19481086e6486dcc028" title="The return type for the thread functions.">wxThread::ExitCode</a>)0; <span class="comment">// success</span></div>
<div class="line">}</div>
</div><!-- fragment --><p>The returned value is the thread exit code which is only useful for joinable threads and is the value returned by <code>"GetThread()->Wait()"</code>.</p>
<p>This function is called by wxWidgets itself and should never be called directly. </p>
</div>
</div>
<a class="anchor" id="ac61fe16deda566773cdc7d4d38709370"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classwx_thread.html">wxThread</a>* wxThreadHelper::GetThread </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</div><div class="memdoc">
<p>This is a public function that returns the <a class="el" href="classwx_thread.html" title="A thread is basically a path of execution through a program.">wxThread</a> object associated with the thread. </p>
</div>
</div>
<a class="anchor" id="ae84f7a6b2bfc7e890d0dfd296cbc43cd"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="interface_2wx_2thread_8h.html#a0dc9a167e8d084946512da99b37b5fd0">wxThreadKind</a> wxThreadHelper::GetThreadKind </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns the last type of thread given to the <a class="el" href="classwx_thread_helper.html#a3682b1b5a08741335aa8acc7feb0ece5" title="Creates a new thread of the given kind.">CreateThread()</a> function or to the constructor. </p>
</div>
</div>
<a class="anchor" id="ad6275bdfa1590d13f4890a433ee3e1c2"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">virtual void wxThreadHelper::OnDelete </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Callback called by Delete() before actually deleting the thread. </p>
<p>This function can be overridden by the derived class to perform some specific task when the thread is gracefully destroyed. Notice that it will be executed in the context of the thread that called Delete() and <b>not</b> in this thread's context.</p>
<p>TestDestroy() will be true for the thread before <a class="el" href="classwx_thread_helper.html#ad6275bdfa1590d13f4890a433ee3e1c2" title="Callback called by Delete() before actually deleting the thread.">OnDelete()</a> gets executed.</p>
<dl class="section since"><dt>Since</dt><dd>2.9.2</dd></dl>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_thread_helper.html#aafc07894e382cbd964c3e9900b2b780b" title="Callback called by Kill() before actually killing the thread.">OnKill()</a> </dd></dl>
</div>
</div>
<a class="anchor" id="aafc07894e382cbd964c3e9900b2b780b"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">virtual void wxThreadHelper::OnKill </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Callback called by Kill() before actually killing the thread. </p>
<p>This function can be overridden by the derived class to perform some specific task when the thread is terminated. Notice that it will be executed in the context of the thread that called Kill() and <b>not</b> in this thread's context.</p>
<dl class="section since"><dt>Since</dt><dd>2.9.2</dd></dl>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_thread_helper.html#ad6275bdfa1590d13f4890a433ee3e1c2" title="Callback called by Delete() before actually deleting the thread.">OnDelete()</a> </dd></dl>
</div>
</div>
</div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:47:00 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>
|