1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>static_thread_pool</title> 5<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../reference.html" title="Reference"> 9<link rel="prev" href="ssl__verify_peer.html" title="ssl::verify_peer"> 10<link rel="next" href="steady_timer.html" title="steady_timer"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td> 15<td align="center"><a href="../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="ssl__verify_peer.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="steady_timer.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_asio.reference.static_thread_pool"></a><a class="link" href="static_thread_pool.html" title="static_thread_pool">static_thread_pool</a> 28</h3></div></div></div> 29<p> 30 <a class="indexterm" name="boost_asio.indexterm.static_thread_pool"></a> 31 </p> 32<pre class="programlisting">typedef thread_pool static_thread_pool; 33</pre> 34<h5> 35<a name="boost_asio.reference.static_thread_pool.h0"></a> 36 <span class="phrase"><a name="boost_asio.reference.static_thread_pool.types"></a></span><a class="link" href="static_thread_pool.html#boost_asio.reference.static_thread_pool.types">Types</a> 37 </h5> 38<div class="informaltable"><table class="table"> 39<colgroup> 40<col> 41<col> 42</colgroup> 43<thead><tr> 44<th> 45 <p> 46 Name 47 </p> 48 </th> 49<th> 50 <p> 51 Description 52 </p> 53 </th> 54</tr></thead> 55<tbody> 56<tr> 57<td> 58 <p> 59 <a class="link" href="thread_pool__basic_executor_type.html" title="thread_pool::basic_executor_type"><span class="bold"><strong>basic_executor_type</strong></span></a> 60 </p> 61 </td> 62<td> 63 <p> 64 Executor implementation type used to submit functions to a thread 65 pool. 66 </p> 67 </td> 68</tr> 69<tr> 70<td> 71 <p> 72 <a class="link" href="thread_pool/executor_type.html" title="thread_pool::executor_type"><span class="bold"><strong>executor_type</strong></span></a> 73 </p> 74 </td> 75<td> 76 <p> 77 Executor used to submit functions to a thread pool. 78 </p> 79 </td> 80</tr> 81<tr> 82<td> 83 <p> 84 <a class="link" href="thread_pool/fork_event.html" title="thread_pool::fork_event"><span class="bold"><strong>fork_event</strong></span></a> 85 </p> 86 </td> 87<td> 88 <p> 89 Fork-related event notifications. 90 </p> 91 </td> 92</tr> 93<tr> 94<td> 95 <p> 96 <a class="link" href="thread_pool/scheduler_type.html" title="thread_pool::scheduler_type"><span class="bold"><strong>scheduler_type</strong></span></a> 97 </p> 98 </td> 99<td> 100 <p> 101 Scheduler used to schedule receivers on a thread pool. 102 </p> 103 </td> 104</tr> 105</tbody> 106</table></div> 107<h5> 108<a name="boost_asio.reference.static_thread_pool.h1"></a> 109 <span class="phrase"><a name="boost_asio.reference.static_thread_pool.member_functions"></a></span><a class="link" href="static_thread_pool.html#boost_asio.reference.static_thread_pool.member_functions">Member 110 Functions</a> 111 </h5> 112<div class="informaltable"><table class="table"> 113<colgroup> 114<col> 115<col> 116</colgroup> 117<thead><tr> 118<th> 119 <p> 120 Name 121 </p> 122 </th> 123<th> 124 <p> 125 Description 126 </p> 127 </th> 128</tr></thead> 129<tbody> 130<tr> 131<td> 132 <p> 133 <a class="link" href="thread_pool/attach.html" title="thread_pool::attach"><span class="bold"><strong>attach</strong></span></a> 134 </p> 135 </td> 136<td> 137 <p> 138 Attaches the current thread to the pool. 139 </p> 140 </td> 141</tr> 142<tr> 143<td> 144 <p> 145 <a class="link" href="thread_pool/executor.html" title="thread_pool::executor"><span class="bold"><strong>executor</strong></span></a> 146 </p> 147 </td> 148<td> 149 <p> 150 Obtains the executor associated with the pool. 151 </p> 152 </td> 153</tr> 154<tr> 155<td> 156 <p> 157 <a class="link" href="thread_pool/get_executor.html" title="thread_pool::get_executor"><span class="bold"><strong>get_executor</strong></span></a> 158 </p> 159 </td> 160<td> 161 <p> 162 Obtains the executor associated with the pool. 163 </p> 164 </td> 165</tr> 166<tr> 167<td> 168 <p> 169 <a class="link" href="thread_pool/join.html" title="thread_pool::join"><span class="bold"><strong>join</strong></span></a> 170 </p> 171 </td> 172<td> 173 <p> 174 Joins the threads. 175 </p> 176 </td> 177</tr> 178<tr> 179<td> 180 <p> 181 <a class="link" href="thread_pool/notify_fork.html" title="thread_pool::notify_fork"><span class="bold"><strong>notify_fork</strong></span></a> 182 </p> 183 </td> 184<td> 185 <p> 186 Notify the execution_context of a fork-related event. 187 </p> 188 </td> 189</tr> 190<tr> 191<td> 192 <p> 193 <a class="link" href="thread_pool/scheduler.html" title="thread_pool::scheduler"><span class="bold"><strong>scheduler</strong></span></a> 194 </p> 195 </td> 196<td> 197 <p> 198 Obtains the scheduler associated with the pool. 199 </p> 200 </td> 201</tr> 202<tr> 203<td> 204 <p> 205 <a class="link" href="thread_pool/stop.html" title="thread_pool::stop"><span class="bold"><strong>stop</strong></span></a> 206 </p> 207 </td> 208<td> 209 <p> 210 Stops the threads. 211 </p> 212 </td> 213</tr> 214<tr> 215<td> 216 <p> 217 <a class="link" href="thread_pool/thread_pool.html" title="thread_pool::thread_pool"><span class="bold"><strong>thread_pool</strong></span></a> <span class="silver">[constructor]</span> 218 </p> 219 </td> 220<td> 221 <p> 222 Constructs a pool with an automatically determined number of threads. 223 <br> <span class="silver"> —</span><br> Constructs a pool with a specified number of threads. 224 </p> 225 </td> 226</tr> 227<tr> 228<td> 229 <p> 230 <a class="link" href="thread_pool/wait.html" title="thread_pool::wait"><span class="bold"><strong>wait</strong></span></a> 231 </p> 232 </td> 233<td> 234 <p> 235 Waits for threads to complete. 236 </p> 237 </td> 238</tr> 239<tr> 240<td> 241 <p> 242 <a class="link" href="thread_pool/_thread_pool.html" title="thread_pool::~thread_pool"><span class="bold"><strong>~thread_pool</strong></span></a> <span class="silver">[destructor]</span> 243 </p> 244 </td> 245<td> 246 <p> 247 Destructor. 248 </p> 249 </td> 250</tr> 251</tbody> 252</table></div> 253<h5> 254<a name="boost_asio.reference.static_thread_pool.h2"></a> 255 <span class="phrase"><a name="boost_asio.reference.static_thread_pool.protected_member_functions"></a></span><a class="link" href="static_thread_pool.html#boost_asio.reference.static_thread_pool.protected_member_functions">Protected 256 Member Functions</a> 257 </h5> 258<div class="informaltable"><table class="table"> 259<colgroup> 260<col> 261<col> 262</colgroup> 263<thead><tr> 264<th> 265 <p> 266 Name 267 </p> 268 </th> 269<th> 270 <p> 271 Description 272 </p> 273 </th> 274</tr></thead> 275<tbody> 276<tr> 277<td> 278 <p> 279 <a class="link" href="thread_pool/destroy.html" title="thread_pool::destroy"><span class="bold"><strong>destroy</strong></span></a> 280 </p> 281 </td> 282<td> 283 <p> 284 Destroys all services in the context. 285 </p> 286 </td> 287</tr> 288<tr> 289<td> 290 <p> 291 <a class="link" href="thread_pool/shutdown.html" title="thread_pool::shutdown"><span class="bold"><strong>shutdown</strong></span></a> 292 </p> 293 </td> 294<td> 295 <p> 296 Shuts down all services in the context. 297 </p> 298 </td> 299</tr> 300</tbody> 301</table></div> 302<h5> 303<a name="boost_asio.reference.static_thread_pool.h3"></a> 304 <span class="phrase"><a name="boost_asio.reference.static_thread_pool.friends"></a></span><a class="link" href="static_thread_pool.html#boost_asio.reference.static_thread_pool.friends">Friends</a> 305 </h5> 306<div class="informaltable"><table class="table"> 307<colgroup> 308<col> 309<col> 310</colgroup> 311<thead><tr> 312<th> 313 <p> 314 Name 315 </p> 316 </th> 317<th> 318 <p> 319 Description 320 </p> 321 </th> 322</tr></thead> 323<tbody> 324<tr> 325<td> 326 <p> 327 <a class="link" href="thread_pool/add_service.html" title="thread_pool::add_service"><span class="bold"><strong>add_service</strong></span></a> 328 </p> 329 </td> 330<td> 331 <p> 332 (Deprecated: Use make_service().) Add a service object to the execution_context. 333 </p> 334 </td> 335</tr> 336<tr> 337<td> 338 <p> 339 <a class="link" href="thread_pool/has_service.html" title="thread_pool::has_service"><span class="bold"><strong>has_service</strong></span></a> 340 </p> 341 </td> 342<td> 343 <p> 344 Determine if an execution_context contains a specified service 345 type. 346 </p> 347 </td> 348</tr> 349<tr> 350<td> 351 <p> 352 <a class="link" href="thread_pool/make_service.html" title="thread_pool::make_service"><span class="bold"><strong>make_service</strong></span></a> 353 </p> 354 </td> 355<td> 356 <p> 357 Creates a service object and adds it to the execution_context. 358 </p> 359 </td> 360</tr> 361<tr> 362<td> 363 <p> 364 <a class="link" href="thread_pool/use_service.html" title="thread_pool::use_service"><span class="bold"><strong>use_service</strong></span></a> 365 </p> 366 </td> 367<td> 368 <p> 369 Obtain the service object corresponding to the given type. 370 </p> 371 </td> 372</tr> 373</tbody> 374</table></div> 375<p> 376 The thread pool class is an execution context where functions are permitted 377 to run on one of a fixed number of threads. 378 </p> 379<h5> 380<a name="boost_asio.reference.static_thread_pool.h4"></a> 381 <span class="phrase"><a name="boost_asio.reference.static_thread_pool.submitting_tasks_to_the_pool"></a></span><a class="link" href="static_thread_pool.html#boost_asio.reference.static_thread_pool.submitting_tasks_to_the_pool">Submitting 382 tasks to the pool</a> 383 </h5> 384<p> 385 To submit functions to the thread pool, use the <a class="link" href="dispatch.html" title="dispatch"><code class="computeroutput">dispatch</code></a> 386 , <a class="link" href="post.html" title="post"><code class="computeroutput">post</code></a> or 387 <a class="link" href="defer.html" title="defer"><code class="computeroutput">defer</code></a> free 388 functions. 389 </p> 390<p> 391 For example: 392 </p> 393<pre class="programlisting">void my_task() 394{ 395 ... 396} 397 398... 399 400// Launch the pool with four threads. 401boost::asio::thread_pool pool(4); 402 403// Submit a function to the pool. 404boost::asio::post(pool, my_task); 405 406// Submit a lambda object to the pool. 407boost::asio::post(pool, 408 []() 409 { 410 ... 411 }); 412 413// Wait for all tasks in the pool to complete. 414pool.join(); 415</pre> 416<h5> 417<a name="boost_asio.reference.static_thread_pool.h5"></a> 418 <span class="phrase"><a name="boost_asio.reference.static_thread_pool.requirements"></a></span><a class="link" href="static_thread_pool.html#boost_asio.reference.static_thread_pool.requirements">Requirements</a> 419 </h5> 420<p> 421 <span class="emphasis"><em>Header: </em></span><code class="literal">boost/asio/static_thread_pool.hpp</code> 422 </p> 423<p> 424 <span class="emphasis"><em>Convenience header: </em></span><code class="literal">boost/asio.hpp</code> 425 </p> 426</div> 427<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 428<td align="left"></td> 429<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 430 Kohlhoff<p> 431 Distributed under the Boost Software License, Version 1.0. (See accompanying 432 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 433 </p> 434</div></td> 435</tr></table> 436<hr> 437<div class="spirit-nav"> 438<a accesskey="p" href="ssl__verify_peer.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="steady_timer.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 439</div> 440</body> 441</html> 442