thread.html 33.0 KB
Newer Older
Y
Yu Yang 已提交
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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
<!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/html; charset=utf-8" />
    
    <title>Lock &mdash; PaddlePaddle  documentation</title>
    
    <link rel="stylesheet" href="../../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="PaddlePaddle  documentation" href="../../index.html" />
    <link rel="up" title="Source Code Documents" href="../index.html" />
    <link rel="next" title="Layer Documents" href="../../layer.html" />
    <link rel="prev" title="Queue" href="queue.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../layer.html" title="Layer Documents"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="queue.html" title="Queue"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PaddlePaddle  documentation</a> &raquo;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Source Code Documents</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="lock">
<h1>Lock<a class="headerlink" href="#lock" title="Permalink to this headline"></a></h1>
<div class="section" id="class-rwlock">
<h2>class RWLock<a class="headerlink" href="#class-rwlock" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="_CPPv2N6paddle6RWLockE">
<span id="paddle::RWLock"></span><span class="target" id="paddleclasspaddle_1_1RWLock"></span><em class="property">class </em><code class="descclassname">paddle::</code><code class="descname">RWLock</code><a class="headerlink" href="#_CPPv2N6paddle6RWLockE" title="Permalink to this definition"></a></dt>
<dd><p>A simple read-write lock. The RWlock allows a number of readers or at most one writer at any point in time. The RWlock disable copy.</p>
<p>Lock:</p>
<p>Use <a class="reference internal" href="#paddleclasspaddle_1_1RWLock_1a6aa591dd56341097550d2424830e151d"><span>lock()</span></a> to lock on write mode, no other thread can get it until unlock.</p>
<p>Use <a class="reference internal" href="#paddleclasspaddle_1_1RWLock_1acd26f9a9bb834456b0a92c63c7193d07"><span>lock_shared()</span></a> to lock on read mode, other thread can get it by using the same method <a class="reference internal" href="#paddleclasspaddle_1_1RWLock_1acd26f9a9bb834456b0a92c63c7193d07"><span>lock_shared()</span></a>.</p>
<p>Unlock:</p>
<p>Use unlock() to unlock the lock. </p>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Public Functions</p>
<dl class="function">
<dt id="_CPPv2N6paddle6RWLock6RWLockEv">
<span id="paddle::RWLock::RWLock"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1af4c6311e9a80a889e933207b5678a9c5"></span><code class="descname">RWLock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle6RWLock6RWLockEv" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle6RWLockD0Ev">
<span id="paddle::RWLock::~RWLock"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1aeaa05b8ff1aab02065c7af2a44961090"></span><code class="descname">~RWLock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle6RWLockD0Ev" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle6RWLock6RWLockERK6RWLock">
<span id="paddle::RWLock::RWLock__RWLockCR"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1a24cb539ee8c117e6d4cdd10cff2e0536"></span><code class="descname">RWLock</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv2N6paddle6RWLock6RWLockEv" title="paddle::RWLock::RWLock">RWLock</a>&amp;<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle6RWLock6RWLockERK6RWLock" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle6RWLockaSERK6RWLock">
<span id="paddle::RWLock::assign-operator__RWLockCR"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1a3ef2a97e32b75e49d2b0ce4b9fb7ffd3"></span><a class="reference internal" href="#_CPPv2N6paddle6RWLock6RWLockEv" title="paddle::RWLock::RWLock">RWLock</a> &amp;<code class="descname">operator=</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv2N6paddle6RWLock6RWLockEv" title="paddle::RWLock::RWLock">RWLock</a>&amp;<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle6RWLockaSERK6RWLock" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle6RWLock4lockEv">
<span id="paddle::RWLock::lock"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1a6aa591dd56341097550d2424830e151d"></span>void <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle6RWLock4lockEv" title="Permalink to this definition"></a></dt>
<dd><p>lock on write mode. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>the method will block the thread, if failed to get the lock. </dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle6RWLock11lock_sharedEv">
<span id="paddle::RWLock::lock_shared"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1acd26f9a9bb834456b0a92c63c7193d07"></span>void <code class="descname">lock_shared</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle6RWLock11lock_sharedEv" title="Permalink to this definition"></a></dt>
<dd><p>lock on read mode. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>if another thread is writing, it can&#8217;t get the lock, and will block the thread. </dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle6RWLock6unlockEv">
<span id="paddle::RWLock::unlock"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1adf535853b7fa46c2ff31e9c65cdd2b19"></span>void <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle6RWLock6unlockEv" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Protected Attributes</p>
<dl class="member">
<dt id="_CPPv2N6paddle6RWLock7rwlock_E">
<span id="paddle::RWLock::rwlock___pthread_rwlock_t"></span><span class="target" id="paddleclasspaddle_1_1RWLock_1a6b9888cd201717a04c6f04e404bd5ff7"></span>pthread_rwlock_t <code class="descname">rwlock_</code><a class="headerlink" href="#_CPPv2N6paddle6RWLock7rwlock_E" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
</dd></dl>

</div>
<div class="section" id="class-readlockguard">
<h2>class ReadLockGuard<a class="headerlink" href="#class-readlockguard" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="_CPPv2N6paddle13ReadLockGuardE">
<span id="paddle::ReadLockGuard"></span><span class="target" id="paddleclasspaddle_1_1ReadLockGuard"></span><em class="property">class </em><code class="descclassname">paddle::</code><code class="descname">ReadLockGuard</code><a class="headerlink" href="#_CPPv2N6paddle13ReadLockGuardE" title="Permalink to this definition"></a></dt>
<dd><p>The <a class="reference internal" href="#paddleclasspaddle_1_1ReadLockGuard"><span>ReadLockGuard</span></a> is a read mode <a class="reference internal" href="#paddleclasspaddle_1_1RWLock"><span>RWLock</span></a> using RAII management mechanism. </p>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Public Functions</p>
<dl class="function">
<dt id="_CPPv2N6paddle13ReadLockGuard13ReadLockGuardER6RWLock">
<span id="paddle::ReadLockGuard::ReadLockGuard__RWLockR"></span><span class="target" id="paddleclasspaddle_1_1ReadLockGuard_1a32d5529beaef9b887b62b98c6e8b39d8"></span><code class="descname">ReadLockGuard</code><span class="sig-paren">(</span><a class="reference internal" href="#_CPPv2N6paddle6RWLockE" title="paddle::RWLock">RWLock</a> &amp;<em>rwlock</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle13ReadLockGuard13ReadLockGuardER6RWLock" title="Permalink to this definition"></a></dt>
<dd><p>Construct Function. Lock on rwlock in read mode. </p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle13ReadLockGuardD0Ev">
<span id="paddle::ReadLockGuard::~ReadLockGuard"></span><span class="target" id="paddleclasspaddle_1_1ReadLockGuard_1a9e7dce579b27cf0af3406dfc0735af3a"></span><code class="descname">~ReadLockGuard</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle13ReadLockGuardD0Ev" title="Permalink to this definition"></a></dt>
<dd><p>Destruct Function. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>This method just unlock the read mode rwlock, won&#8217;t destroy the lock. </dd>
</dl>
</p>
</dd></dl>

</div>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Protected Attributes</p>
<dl class="member">
<dt id="_CPPv2N6paddle13ReadLockGuard7rwlock_E">
<span id="paddle::ReadLockGuard::rwlock___RWLockP"></span><span class="target" id="paddleclasspaddle_1_1ReadLockGuard_1aee09e7988bb849e33647945d255a4b9a"></span><a class="reference internal" href="#_CPPv2N6paddle6RWLockE" title="paddle::RWLock">RWLock</a> *<code class="descname">rwlock_</code><a class="headerlink" href="#_CPPv2N6paddle13ReadLockGuard7rwlock_E" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
</dd></dl>

</div>
<div class="section" id="class-spinlock">
<h2>class SpinLock<a class="headerlink" href="#class-spinlock" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="_CPPv2N6paddle8SpinLockE">
<span id="paddle::SpinLock"></span><span class="target" id="paddleclasspaddle_1_1SpinLock"></span><em class="property">class </em><code class="descclassname">paddle::</code><code class="descname">SpinLock</code><a class="headerlink" href="#_CPPv2N6paddle8SpinLockE" title="Permalink to this definition"></a></dt>
<dd><p>A simple wrapper for spin lock. The lock() method of <a class="reference internal" href="#paddleclasspaddle_1_1SpinLock"><span>SpinLock</span></a> is busy-waiting which means it will keep trying to lock until lock on successfully. The <a class="reference internal" href="#paddleclasspaddle_1_1SpinLock"><span>SpinLock</span></a> disable copy. </p>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Public Functions</p>
<dl class="function">
<dt id="_CPPv2N6paddle8SpinLock8SpinLockEv">
<span id="paddle::SpinLock::SpinLock"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1ae4b8664661115cae5d7a9f5c1e4cd4ed"></span><code class="descname">SpinLock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle8SpinLock8SpinLockEv" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle8SpinLockD0Ev">
<span id="paddle::SpinLock::~SpinLock"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1a12800af3f93511270eceba996f2e1233"></span><code class="descname">~SpinLock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle8SpinLockD0Ev" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle8SpinLock8SpinLockERK8SpinLock">
<span id="paddle::SpinLock::SpinLock__SpinLockCR"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1a055efdc5fa3c87bf9c5efa19ca91fceb"></span><code class="descname">SpinLock</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv2N6paddle8SpinLock8SpinLockEv" title="paddle::SpinLock::SpinLock">SpinLock</a>&amp;<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle8SpinLock8SpinLockERK8SpinLock" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle8SpinLockaSERK8SpinLock">
<span id="paddle::SpinLock::assign-operator__SpinLockCR"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1a65860c4525eafaf6c50f67bb7e6f1217"></span><a class="reference internal" href="#_CPPv2N6paddle8SpinLock8SpinLockEv" title="paddle::SpinLock::SpinLock">SpinLock</a> &amp;<code class="descname">operator=</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv2N6paddle8SpinLock8SpinLockEv" title="paddle::SpinLock::SpinLock">SpinLock</a>&amp;<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle8SpinLockaSERK8SpinLock" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle8SpinLock4lockEv">
<span id="paddle::SpinLock::lock"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1ae5b78520a7808c9eee28674fa2dc1196"></span>void <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle8SpinLock4lockEv" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle8SpinLock6unlockEv">
<span id="paddle::SpinLock::unlock"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1a14f55be9684bed14427537571e7b6f7a"></span>void <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle8SpinLock6unlockEv" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Protected Attributes</p>
<dl class="member">
<dt id="_CPPv2N6paddle8SpinLock5lock_E">
<span id="paddle::SpinLock::lock___pthread_spinlock_t"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1a262929588dcc81d1740094988782f57e"></span>pthread_spinlock_t <code class="descname">lock_</code><a class="headerlink" href="#_CPPv2N6paddle8SpinLock5lock_E" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="member">
<dt id="_CPPv2N6paddle8SpinLock8padding_E">
<span id="paddle::SpinLock::padding___cA"></span><span class="target" id="paddleclasspaddle_1_1SpinLock_1a8c0dd8c3d3959525ecb169db292382ec"></span>char <code class="descname">padding_</code>[64-sizeof(pthread_spinlock_t)]<a class="headerlink" href="#_CPPv2N6paddle8SpinLock8padding_E" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
</dd></dl>

</div>
<div class="section" id="class-semaphore">
<h2>class Semaphore<a class="headerlink" href="#class-semaphore" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="_CPPv2N6paddle9SemaphoreE">
<span id="paddle::Semaphore"></span><span class="target" id="paddleclasspaddle_1_1Semaphore"></span><em class="property">class </em><code class="descclassname">paddle::</code><code class="descname">Semaphore</code><a class="headerlink" href="#_CPPv2N6paddle9SemaphoreE" title="Permalink to this definition"></a></dt>
<dd><p>A simple wapper of semaphore which can only be shared in the same process. </p>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Public Functions</p>
<dl class="function">
<dt id="_CPPv2N6paddle9Semaphore9SemaphoreEi">
<span id="paddle::Semaphore::Semaphore__i"></span><span class="target" id="paddleclasspaddle_1_1Semaphore_1a4884c28f1f853a0467b70e7f33547670"></span><code class="descname">Semaphore</code><span class="sig-paren">(</span>int <em>initValue</em> = 0<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle9Semaphore9SemaphoreEi" title="Permalink to this definition"></a></dt>
<dd><p>Construct Function. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last">
<li><code class="first docutils literal"><span class="pre">initValue</span></code> - <p>the initial value of the semaphore, default 0. </p>
</li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle9SemaphoreD0Ev">
<span id="paddle::Semaphore::~Semaphore"></span><span class="target" id="paddleclasspaddle_1_1Semaphore_1a3cc7ae229c74573a3f1b8f1c4749bf1e"></span><code class="descname">~Semaphore</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle9SemaphoreD0Ev" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle9Semaphore8timeWaitEP8timespec">
<span id="paddle::Semaphore::timeWait__timespecP"></span><span class="target" id="paddleclasspaddle_1_1Semaphore_1ac2ac4a112be6a02c51e1429d98e626e5"></span>bool <code class="descname">timeWait</code><span class="sig-paren">(</span><em class="property">struct</em> timespec *<em>ts</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle9Semaphore8timeWaitEP8timespec" title="Permalink to this definition"></a></dt>
<dd><p>The same as <a class="reference internal" href="#paddleclasspaddle_1_1Semaphore_1a3d7d3699ad8f49ad8bbad260a174c28d"><span>wait()</span></a>, except if the decrement can not be performed until ts return false install of blocking. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>ture if the decrement proceeds before ts, else return false. </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last">
<li><code class="first docutils literal"><span class="pre">ts</span></code> - <p>an absolute timeout in seconds and nanoseconds since the Epoch 1970-01-01 00:00:00 +0000(UTC). </p>
</li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle9Semaphore4waitEv">
<span id="paddle::Semaphore::wait"></span><span class="target" id="paddleclasspaddle_1_1Semaphore_1a3d7d3699ad8f49ad8bbad260a174c28d"></span>void <code class="descname">wait</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle9Semaphore4waitEv" title="Permalink to this definition"></a></dt>
<dd><p>decrement the semaphore. If the semaphore&#8217;s value is 0, then call blocks. </p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle9Semaphore4postEv">
<span id="paddle::Semaphore::post"></span><span class="target" id="paddleclasspaddle_1_1Semaphore_1a17c46402c18a2f58529f22aac0769cc1"></span>void <code class="descname">post</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle9Semaphore4postEv" title="Permalink to this definition"></a></dt>
<dd><p>increment the semaphore. If the semaphore&#8217;s value greater than 0, wake up a thread blocked in <a class="reference internal" href="#paddleclasspaddle_1_1Semaphore_1a3d7d3699ad8f49ad8bbad260a174c28d"><span>wait()</span></a>. </p>
</dd></dl>

</div>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Protected Attributes</p>
<dl class="member">
<dt id="_CPPv2N6paddle9Semaphore4sem_E">
<span id="paddle::Semaphore::sem___sem_t"></span><span class="target" id="paddleclasspaddle_1_1Semaphore_1ab66cee48c4a02d13b4ef56cf2538ee42"></span>sem_t <code class="descname">sem_</code><a class="headerlink" href="#_CPPv2N6paddle9Semaphore4sem_E" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
</dd></dl>

</div>
<div class="section" id="class-threadbarrier">
<h2>class ThreadBarrier<a class="headerlink" href="#class-threadbarrier" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="_CPPv2N6paddle13ThreadBarrierE">
<span id="paddle::ThreadBarrier"></span><span class="target" id="paddleclasspaddle_1_1ThreadBarrier"></span><em class="property">class </em><code class="descclassname">paddle::</code><code class="descname">ThreadBarrier</code><a class="headerlink" href="#_CPPv2N6paddle13ThreadBarrierE" title="Permalink to this definition"></a></dt>
<dd><p>A simple wrapper of thread barrier. The <a class="reference internal" href="#paddleclasspaddle_1_1ThreadBarrier"><span>ThreadBarrier</span></a> disable copy. </p>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Public Functions</p>
<dl class="function">
<dt id="_CPPv2N6paddle13ThreadBarrier13ThreadBarrierEi">
<span id="paddle::ThreadBarrier::ThreadBarrier__i"></span><span class="target" id="paddleclasspaddle_1_1ThreadBarrier_1a2b4ee1af9857ce417455d6a343a1a117"></span><code class="descname">ThreadBarrier</code><span class="sig-paren">(</span>int <em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle13ThreadBarrier13ThreadBarrierEi" title="Permalink to this definition"></a></dt>
<dd><p>Construct Function. Initialize the barrier should wait for count threads in <a class="reference internal" href="#paddleclasspaddle_1_1ThreadBarrier_1af63f9491d2644a258350e12120fedf89"><span>wait()</span></a>. </p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle13ThreadBarrierD0Ev">
<span id="paddle::ThreadBarrier::~ThreadBarrier"></span><span class="target" id="paddleclasspaddle_1_1ThreadBarrier_1a0922960555e03da24426cf8fdd0b15dd"></span><code class="descname">~ThreadBarrier</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle13ThreadBarrierD0Ev" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle13ThreadBarrier13ThreadBarrierERK13ThreadBarrier">
<span id="paddle::ThreadBarrier::ThreadBarrier__ThreadBarrierCR"></span><span class="target" id="paddleclasspaddle_1_1ThreadBarrier_1a42b7d18074508549f5e53156d8791fd8"></span><code class="descname">ThreadBarrier</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv2N6paddle13ThreadBarrier13ThreadBarrierEi" title="paddle::ThreadBarrier::ThreadBarrier">ThreadBarrier</a>&amp;<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle13ThreadBarrier13ThreadBarrierERK13ThreadBarrier" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle13ThreadBarrieraSERK13ThreadBarrier">
<span id="paddle::ThreadBarrier::assign-operator__ThreadBarrierCR"></span><span class="target" id="paddleclasspaddle_1_1ThreadBarrier_1a84b0ef2c24d0ee7770fa453d385f5bdf"></span><a class="reference internal" href="#_CPPv2N6paddle13ThreadBarrier13ThreadBarrierEi" title="paddle::ThreadBarrier::ThreadBarrier">ThreadBarrier</a> &amp;<code class="descname">operator=</code><span class="sig-paren">(</span><em class="property">const</em> <a class="reference internal" href="#_CPPv2N6paddle13ThreadBarrier13ThreadBarrierEi" title="paddle::ThreadBarrier::ThreadBarrier">ThreadBarrier</a>&amp;<span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle13ThreadBarrieraSERK13ThreadBarrier" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle13ThreadBarrier4waitEv">
<span id="paddle::ThreadBarrier::wait"></span><span class="target" id="paddleclasspaddle_1_1ThreadBarrier_1af63f9491d2644a258350e12120fedf89"></span>void <code class="descname">wait</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle13ThreadBarrier4waitEv" title="Permalink to this definition"></a></dt>
<dd><p>If there were count - 1 threads waiting before, then wake up all the count - 1 threads and continue run together. Else block the thread until waked by other thread . </p>
</dd></dl>

</div>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Protected Attributes</p>
<dl class="member">
<dt id="_CPPv2N6paddle13ThreadBarrier8barrier_E">
<span id="paddle::ThreadBarrier::barrier___pthread_barrier_t"></span><span class="target" id="paddleclasspaddle_1_1ThreadBarrier_1ae29548e35c5a20906647e8dcc48f9f39"></span>pthread_barrier_t <code class="descname">barrier_</code><a class="headerlink" href="#_CPPv2N6paddle13ThreadBarrier8barrier_E" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
</dd></dl>

</div>
<div class="section" id="class-lockedcondition">
<h2>class LockedCondition<a class="headerlink" href="#class-lockedcondition" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="_CPPv2N6paddle15LockedConditionE">
<span id="paddle::LockedCondition"></span><span class="target" id="paddleclasspaddle_1_1LockedCondition"></span><em class="property">class </em><code class="descclassname">paddle::</code><code class="descname">LockedCondition</code><a class="headerlink" href="#_CPPv2N6paddle15LockedConditionE" title="Permalink to this definition"></a></dt>
<dd><p>A wrapper for condition variable with mutex. </p>
<p>Inherits from condition_variable</p>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Public Functions</p>
<dl class="function">
<dt>
<em class="property">template </em>&lt;<em class="property">class</em> Op&gt;</dt>
<dt id="_CPPv2N6paddle15LockedCondition10notify_oneE2Op">
<span id="paddle::LockedCondition::notify_one__Op"></span><span class="target" id="paddleclasspaddle_1_1LockedCondition_1a54d725c12dbd1dcf9a37d6b41bf8d226"></span>void <code class="descname">notify_one</code><span class="sig-paren">(</span>Op <em>op</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle15LockedCondition10notify_oneE2Op" title="Permalink to this definition"></a></dt>
<dd><p>execute op and notify one thread which was blocked. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last">
<li><code class="first docutils literal"><span class="pre">op</span></code> - <p>a thread can do something in op before notify. </p>
</li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt>
<em class="property">template </em>&lt;<em class="property">class</em> Op&gt;</dt>
<dt id="_CPPv2N6paddle15LockedCondition10notify_allE2Op">
<span id="paddle::LockedCondition::notify_all__Op"></span><span class="target" id="paddleclasspaddle_1_1LockedCondition_1ad08bfa60f14da940a3a530c27a43e15c"></span>void <code class="descname">notify_all</code><span class="sig-paren">(</span>Op <em>op</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle15LockedCondition10notify_allE2Op" title="Permalink to this definition"></a></dt>
<dd><p>execute op and notify all the threads which were blocked. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last">
<li><code class="first docutils literal"><span class="pre">op</span></code> - <p>a thread can do something in op before notify. </p>
</li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt>
<em class="property">template </em>&lt;<em class="property">class</em> Predicate&gt;</dt>
<dt id="_CPPv2N6paddle15LockedCondition4waitE9Predicate">
<span id="paddle::LockedCondition::wait__Predicate"></span><span class="target" id="paddleclasspaddle_1_1LockedCondition_1aa866a488e0bddc26108f39af77dc9012"></span>void <code class="descname">wait</code><span class="sig-paren">(</span>Predicate <em>pred</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle15LockedCondition4waitE9Predicate" title="Permalink to this definition"></a></dt>
<dd><p>wait until pred return ture. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>pred shall not apply any non-constant function through the dereferenced iterator. </dd>
<dt><strong>Template Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last">
<li><code class="first docutils literal"><span class="pre">Predicate</span></code> - <p>c++ concepts, describes a function object that takes a single iterator argument that is dereferenced and used to return a value testable as a bool. </p>
</li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv2N6paddle15LockedCondition5mutexEv">
<span id="paddle::LockedCondition::mutex"></span><span class="target" id="paddleclasspaddle_1_1LockedCondition_1a444e6686d4e02b9a539d33093063216f"></span>std::mutex *<code class="descname">mutex</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv2N6paddle15LockedCondition5mutexEv" title="Permalink to this definition"></a></dt>
<dd><p>get mutex. </p>
</dd></dl>

</div>
<div class="breathe-sectiondef container">
<p class="breathe-sectiondef-title rubric">Protected Attributes</p>
<dl class="member">
<dt id="_CPPv2N6paddle15LockedCondition6mutex_E">
<span id="paddle::LockedCondition::mutex___std::mutex"></span><span class="target" id="paddleclasspaddle_1_1LockedCondition_1a7ec0d582f0c06e942c9f214e9c074f23"></span>std::mutex <code class="descname">mutex_</code><a class="headerlink" href="#_CPPv2N6paddle15LockedCondition6mutex_E" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

</div>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Lock</a><ul>
<li><a class="reference internal" href="#class-rwlock">class RWLock</a></li>
<li><a class="reference internal" href="#class-readlockguard">class ReadLockGuard</a></li>
<li><a class="reference internal" href="#class-spinlock">class SpinLock</a></li>
<li><a class="reference internal" href="#class-semaphore">class Semaphore</a></li>
<li><a class="reference internal" href="#class-threadbarrier">class ThreadBarrier</a></li>
<li><a class="reference internal" href="#class-lockedcondition">class LockedCondition</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="queue.html"
                        title="previous chapter">Queue</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../../layer.html"
                        title="next chapter">Layer Documents</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/source/utils/thread.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../layer.html" title="Layer Documents"
             >next</a> |</li>
        <li class="right" >
          <a href="queue.html" title="Queue"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">PaddlePaddle  documentation</a> &raquo;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >Source Code Documents</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2016, PaddlePaddle developers.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
    </div>
  </body>
</html>