123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/threadpool</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
- <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/threadpool</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li><a class="reference" id="see-also_toc" href="#see-also">See also</a></li>
- <li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#FlowVar" title="FlowVar[T] {.compilerproc.} = ref FlowVarObj[T]">FlowVar</a></li>
- <li><a class="reference" href="#FlowVarBase" title="FlowVarBase = ref FlowVarBaseObj">FlowVarBase</a></li>
- <li><a class="reference" href="#ThreadId" title="ThreadId = range[0 .. MaxDistinguishedThread - 1]">ThreadId</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#MaxDistinguishedThread" title="MaxDistinguishedThread {.intdefine.} = 32">MaxDistinguishedThread</a></li>
- <li><a class="reference" href="#MaxThreadPoolSize" title="MaxThreadPoolSize {.intdefine.} = 256">MaxThreadPoolSize</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">^
- <li><a class="reference" href="#%5E%2CFlowVar%5BT%5D" title="`^`[T](fv: FlowVar[T]): T">`^`[T](fv: FlowVar[T]): T</a></li>
- </ul>
- <ul class="simple nested-toc-section">awaitAndThen
- <li><a class="reference" href="#awaitAndThen%2CFlowVar%5BT%5D%2Cproc%28T%29" title="awaitAndThen[T](fv: FlowVar[T]; action: proc (x: T) {.closure.})">awaitAndThen[T](fv: FlowVar[T]; action: proc (x: T) {.closure.})</a></li>
- </ul>
- <ul class="simple nested-toc-section">blockUntil
- <li><a class="reference" href="#blockUntil%2CFlowVarBaseObj" title="blockUntil(fv: var FlowVarBaseObj)">blockUntil(fv: var FlowVarBaseObj)</a></li>
- </ul>
- <ul class="simple nested-toc-section">blockUntilAny
- <li><a class="reference" href="#blockUntilAny%2CopenArray%5BFlowVarBase%5D" title="blockUntilAny(flowVars: openArray[FlowVarBase]): int">blockUntilAny(flowVars: openArray[FlowVarBase]): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">isReady
- <li><a class="reference" href="#isReady%2CFlowVarBase" title="isReady(fv: FlowVarBase): bool">isReady(fv: FlowVarBase): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">parallel
- <li><a class="reference" href="#parallel%2Cuntyped" title="parallel(body: untyped)">parallel(body: untyped)</a></li>
- </ul>
- <ul class="simple nested-toc-section">pinnedSpawn
- <li><a class="reference" href="#pinnedSpawn%2CThreadId%2Csinktyped" title="pinnedSpawn(id: ThreadId; call: sink typed)">pinnedSpawn(id: ThreadId; call: sink typed)</a></li>
- </ul>
- <ul class="simple nested-toc-section">preferSpawn
- <li><a class="reference" href="#preferSpawn" title="preferSpawn(): bool">preferSpawn(): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">setMaxPoolSize
- <li><a class="reference" href="#setMaxPoolSize%2Crange%5B%5D" title="setMaxPoolSize(size: range[1 .. MaxThreadPoolSize])">setMaxPoolSize(size: range[1 .. MaxThreadPoolSize])</a></li>
- </ul>
- <ul class="simple nested-toc-section">setMinPoolSize
- <li><a class="reference" href="#setMinPoolSize%2Crange%5B%5D" title="setMinPoolSize(size: range[1 .. MaxThreadPoolSize])">setMinPoolSize(size: range[1 .. MaxThreadPoolSize])</a></li>
- </ul>
- <ul class="simple nested-toc-section">spawn
- <li><a class="reference" href="#spawn%2Csinktyped" title="spawn(call: sink typed)">spawn(call: sink typed)</a></li>
- </ul>
- <ul class="simple nested-toc-section">sync
- <li><a class="reference" href="#sync" title="sync()">sync()</a></li>
- </ul>
- <ul class="simple nested-toc-section">unsafeRead
- <li><a class="reference" href="#unsafeRead%2CFlowVar%5Bref.T%5D" title="unsafeRead[T](fv: FlowVar[ref T]): ptr T">unsafeRead[T](fv: FlowVar[ref T]): ptr T</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">spawnX
- <li><a class="reference" href="#spawnX.t" title="spawnX(call)">spawnX(call)</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
- <div class="deprecation-message">
- <b>Deprecated:</b> use the nimble packages `malebolgia`, `taskpools` or `weave` instead
- </div>
- <p class="module-desc"><p>Implements Nim's <a class="reference external" href="manual_experimental.html#parallel-amp-spawn">parallel & spawn statements</a>.</p>
- <p>Unstable API.</p>
- <h1><a class="toc-backref" id="see-also" href="#see-also">See also</a></h1><ul class="simple"><li><a class="reference external" href="typedthreads.html">threads module</a> for basic thread support</li>
- <li><a class="reference external" href="locks.html">locks module</a> for locks and condition variables</li>
- <li><a class="reference external" href="asyncdispatch.html">asyncdispatch module</a> for asynchronous IO</li>
- </ul>
- </p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="cpuinfo.html">cpuinfo</a>, <a class="reference external" href="cpuload.html">cpuload</a>, <a class="reference external" href="locks.html">locks</a>, <a class="reference external" href="os.html">os</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="typedthreads.html">typedthreads</a>, <a class="reference external" href="sysatomics.html">sysatomics</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="FlowVar">
- <dt><pre><a href="threadpool.html#FlowVar"><span class="Identifier">FlowVar</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> {.<span class="Identifier">compilerproc</span>.} <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Identifier">FlowVarObj</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span></pre></dt>
- <dd>
-
- A data flow variable.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L119" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L119" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="FlowVarBase">
- <dt><pre><a href="threadpool.html#FlowVarBase"><span class="Identifier">FlowVarBase</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Identifier">FlowVarBaseObj</span></pre></dt>
- <dd>
-
- Untyped base class for <a class="reference external" href="#FlowVar">FlowVar[T]</a>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L106" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L106" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="ThreadId">
- <dt><pre><a href="threadpool.html#ThreadId"><span class="Identifier">ThreadId</span></a> <span class="Other">=</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <a href="threadpool.html#MaxDistinguishedThread"><span class="Identifier">MaxDistinguishedThread</span></a> <span class="Operator">-</span> <span class="DecNumber">1</span><span class="Other">]</span></pre></dt>
- <dd>
-
- A thread identifier.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L322" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L322" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="10">
- <h1><a class="toc-backref" href="#10">Consts</a></h1>
- <dl class="item">
- <div id="MaxDistinguishedThread">
- <dt><pre><a href="threadpool.html#MaxDistinguishedThread"><span class="Identifier">MaxDistinguishedThread</span></a> {.<span class="Identifier">intdefine</span>.} <span class="Other">=</span> <span class="DecNumber">32</span></pre></dt>
- <dd>
-
- Maximum number of "distinguished" threads.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L319" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L319" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="MaxThreadPoolSize">
- <dt><pre><a href="threadpool.html#MaxThreadPoolSize"><span class="Identifier">MaxThreadPoolSize</span></a> {.<span class="Identifier">intdefine</span>.} <span class="Other">=</span> <span class="DecNumber">256</span></pre></dt>
- <dd>
-
- Maximum size of the thread pool. 256 threads should be good enough for anybody ;-)
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L317" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L317" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="^-procs-all">
- <div id="^,FlowVar[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5E%2CFlowVar%5BT%5D"><span class="Identifier">`^`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">fv</span><span class="Other">:</span> <a href="threadpool.html#FlowVar"><span class="Identifier">FlowVar</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
- <dd>
-
- Blocks until the value is available and then returns this value.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L263" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L263" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="awaitAndThen-procs-all">
- <div id="awaitAndThen,FlowVar[T],proc(T)">
- <dt><pre><span class="Keyword">proc</span> <a href="#awaitAndThen%2CFlowVar%5BT%5D%2Cproc%28T%29"><span class="Identifier">awaitAndThen</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">fv</span><span class="Other">:</span> <a href="threadpool.html#FlowVar"><span class="Identifier">FlowVar</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">action</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span> {.<span class="Identifier">closure</span>.}<span class="Other">)</span></pre></dt>
- <dd>
-
- <p>Blocks until <tt class="docutils literal"><span class="pre"><span class="Identifier">fv</span></span></tt> is available and then passes its value to <tt class="docutils literal"><span class="pre"><span class="Identifier">action</span></span></tt>.</p>
- <p>Note that due to Nim's parameter passing semantics, this means that <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt> doesn't need to be copied, so <tt class="docutils literal"><span class="pre"><span class="Identifier">awaitAndThen</span></span></tt> can sometimes be more efficient than the <a class="reference external" href="#^,FlowVar[T]">^ proc</a>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L236" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L236" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="blockUntil-procs-all">
- <div id="blockUntil,FlowVarBaseObj">
- <dt><pre><span class="Keyword">proc</span> <a href="#blockUntil%2CFlowVarBaseObj"><span class="Identifier">blockUntil</span></a><span class="Other">(</span><span class="Identifier">fv</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">FlowVarBaseObj</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Waits until the value for <tt class="docutils literal"><span class="pre"><span class="Identifier">fv</span></span></tt> arrives.</p>
- <p>Usually it is not necessary to call this explicitly.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L142" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L142" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="blockUntilAny-procs-all">
- <div id="blockUntilAny,openArray[FlowVarBase]">
- <dt><pre><span class="Keyword">proc</span> <a href="#blockUntilAny%2CopenArray%5BFlowVarBase%5D"><span class="Identifier">blockUntilAny</span></a><span class="Other">(</span><span class="Identifier">flowVars</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><a href="threadpool.html#FlowVarBase"><span class="Identifier">FlowVarBase</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Awaits any of the given <tt class="docutils literal"><span class="pre"><span class="Identifier">flowVars</span></span></tt>. Returns the index of one <tt class="docutils literal"><span class="pre"><span class="Identifier">flowVar</span></span></tt> for which a value arrived.</p>
- <p>A <tt class="docutils literal"><span class="pre"><span class="Identifier">flowVar</span></span></tt> only supports one call to <tt class="docutils literal"><span class="pre"><span class="Identifier">blockUntilAny</span></span></tt> at the same time. That means if you <tt class="docutils literal"><span class="pre"><span class="Identifier">blockUntilAny</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="Identifier">a</span><span class="Punctuation">,</span><span class="Identifier">b</span><span class="Punctuation">]</span><span class="Punctuation">)</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">blockUntilAny</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="Identifier">b</span><span class="Punctuation">,</span><span class="Identifier">c</span><span class="Punctuation">]</span><span class="Punctuation">)</span></span></tt> the second call will only block until <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt>. If there is no <tt class="docutils literal"><span class="pre"><span class="Identifier">flowVar</span></span></tt> left to be able to wait on, -1 is returned.</p>
- <p><strong>Note:</strong> This results in non-deterministic behaviour and should be avoided.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L272" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L272" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="isReady-procs-all">
- <div id="isReady,FlowVarBase">
- <dt><pre><span class="Keyword">proc</span> <a href="#isReady%2CFlowVarBase"><span class="Identifier">isReady</span></a><span class="Other">(</span><span class="Identifier">fv</span><span class="Other">:</span> <a href="threadpool.html#FlowVarBase"><span class="Identifier">FlowVarBase</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Determines whether the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">FlowVarBase</span></span></tt>'s value is available.</p>
- <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt>, awaiting <tt class="docutils literal"><span class="pre"><span class="Identifier">fv</span></span></tt> will not block.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L301" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L301" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="parallel-procs-all">
- <div id="parallel,untyped">
- <dt><pre><span class="Keyword">proc</span> <a href="#parallel%2Cuntyped"><span class="Identifier">parallel</span></a><span class="Other">(</span><span class="Identifier">body</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a><span class="Other">)</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"Parallel"</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>A parallel section can be used to execute a block in parallel.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">body</span></span></tt> has to be in a DSL that is a particular subset of the language.</p>
- <p>Please refer to <a class="reference external" href="manual_experimental.html#parallel-amp-spawn">the manual</a> for further information.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L484" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L484" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="pinnedSpawn-procs-all">
- <div id="pinnedSpawn,ThreadId,sinktyped">
- <dt><pre><span class="Keyword">proc</span> <a href="#pinnedSpawn%2CThreadId%2Csinktyped"><span class="Identifier">pinnedSpawn</span></a><span class="Other">(</span><span class="Identifier">id</span><span class="Other">:</span> <a href="threadpool.html#ThreadId"><span class="Identifier">ThreadId</span></a><span class="Other">;</span> <span class="Identifier">call</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">)</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"Spawn"</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Always spawns a new task on the worker thread with <tt class="docutils literal"><span class="pre"><span class="Identifier">id</span></span></tt>, so that the <tt class="docutils literal"><span class="pre"><span class="Identifier">call</span></span></tt> is <strong>always</strong> executed on the thread.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">call</span></span></tt> has to be a proc call <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span><span class="Punctuation">(</span><span class="Operator">...</span><span class="Punctuation">)</span></span></tt> where <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt> is gcsafe and has a return type that is either <tt class="docutils literal"><span class="pre"><span class="Identifier">void</span></span></tt> or compatible with <tt class="docutils literal"><span class="pre"><span class="Identifier">FlowVar</span><span class="Punctuation">[</span><span class="Identifier">T</span><span class="Punctuation">]</span></span></tt>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L465" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L465" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="preferSpawn-procs-all">
- <div id="preferSpawn">
- <dt><pre><span class="Keyword">proc</span> <a href="#preferSpawn"><span class="Identifier">preferSpawn</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Use this proc to determine quickly if a <tt class="docutils literal"><span class="pre"><span class="Identifier">spawn</span></span></tt> or a direct call is preferable.</p>
- <p>If it returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt>, a <tt class="docutils literal"><span class="pre"><span class="Identifier">spawn</span></span></tt> may make sense. In general it is not necessary to call this directly; use the <a class="reference external" href="#spawnX.t">spawnX template</a> instead.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L448" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L448" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="setMaxPoolSize-procs-all">
- <div id="setMaxPoolSize,range[]">
- <dt><pre><span class="Keyword">proc</span> <a href="#setMaxPoolSize%2Crange%5B%5D"><span class="Identifier">setMaxPoolSize</span></a><span class="Other">(</span><span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="Identifier">MaxThreadPoolSize</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Sets the maximum thread pool size. The default value of this is <a class="reference external" href="#MaxThreadPoolSize">MaxThreadPoolSize</a>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L407" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L407" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="setMinPoolSize-procs-all">
- <div id="setMinPoolSize,range[]">
- <dt><pre><span class="Keyword">proc</span> <a href="#setMinPoolSize%2Crange%5B%5D"><span class="Identifier">setMinPoolSize</span></a><span class="Other">(</span><span class="Identifier">size</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="Identifier">MaxThreadPoolSize</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
- <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- Sets the minimum thread pool size. The default value of this is 4.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L403" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L403" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="spawn-procs-all">
- <div id="spawn,sinktyped">
- <dt><pre><span class="Keyword">proc</span> <a href="#spawn%2Csinktyped"><span class="Identifier">spawn</span></a><span class="Other">(</span><span class="Identifier">call</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">)</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"Spawn"</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>Always spawns a new task, so that the <tt class="docutils literal"><span class="pre"><span class="Identifier">call</span></span></tt> is never executed on the calling thread.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">call</span></span></tt> has to be a proc call <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span><span class="Punctuation">(</span><span class="Operator">...</span><span class="Punctuation">)</span></span></tt> where <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt> is gcsafe and has a return type that is either <tt class="docutils literal"><span class="pre"><span class="Identifier">void</span></span></tt> or compatible with <tt class="docutils literal"><span class="pre"><span class="Identifier">FlowVar</span><span class="Punctuation">[</span><span class="Identifier">T</span><span class="Punctuation">]</span></span></tt>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L457" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L457" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="sync-procs-all">
- <div id="sync">
- <dt><pre><span class="Keyword">proc</span> <a href="#sync"><span class="Identifier">sync</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
- <dd>
-
- <p>A simple barrier to wait for all <tt class="docutils literal"><span class="pre"><span class="Identifier">spawn</span></span></tt>ed tasks.</p>
- <p>If you need more elaborate waiting, you have to use an explicit barrier.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L593" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L593" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="unsafeRead-procs-all">
- <div id="unsafeRead,FlowVar[ref.T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#unsafeRead%2CFlowVar%5Bref.T%5D"><span class="Identifier">unsafeRead</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">fv</span><span class="Other">:</span> <a href="threadpool.html#FlowVar"><span class="Identifier">FlowVar</span></a><span class="Other">[</span><span class="Keyword">ref</span> <span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">ptr</span> <span class="Identifier">T</span></pre></dt>
- <dd>
-
- Blocks until the value is available and then returns this value.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L254" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L254" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="18">
- <h1><a class="toc-backref" href="#18">Templates</a></h1>
- <dl class="item">
- <div id="spawnX-templates-all">
- <div id="spawnX.t">
- <dt><pre><span class="Keyword">template</span> <a href="#spawnX.t"><span class="Identifier">spawnX</span></a><span class="Other">(</span><span class="Identifier">call</span><span class="Other">)</span></pre></dt>
- <dd>
-
- <p>Spawns a new task if a CPU core is ready, otherwise executes the call in the calling thread.</p>
- <p>Usually, it is advised to use the <a class="reference external" href="#spawn,sinktyped">spawn proc</a> in order to not block the producer for an unknown amount of time.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">call</span></span></tt> has to be a proc call <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span><span class="Punctuation">(</span><span class="Operator">...</span><span class="Punctuation">)</span></span></tt> where <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt> is gcsafe and has a return type that is either 'void' or compatible with <tt class="docutils literal"><span class="pre"><span class="Identifier">FlowVar</span><span class="Punctuation">[</span><span class="Identifier">T</span><span class="Punctuation">]</span></span></tt>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/concurrency/threadpool.nim#L473" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/concurrency/threadpool.nim#L473" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-03-15 14:13:35 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|