mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
281 lines
28 KiB
HTML
281 lines
28 KiB
HTML
<?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/typedthreads</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/typedthreads</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="examples_toc" href="#examples">Examples</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="#12" id="62">Procs</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<ul class="simple nested-toc-section">createThread
|
|
<li><a class="reference" href="#createThread%2CThread%5Bvoid%5D%2Cproc%29" title="createThread(t: var Thread[void]; tp: proc () {.thread, nimcall.})">createThread(t: var Thread[void]; tp: proc () {.thread, nimcall.})</a></li>
|
|
<li><a class="reference" href="#createThread%2CThread%5BTArg%5D%2Cproc%28TArg%29%2CTArg" title="createThread[TArg](t: var Thread[TArg]; tp: proc (arg: TArg) {.thread, nimcall.};
|
|
param: TArg)">createThread[TArg](t: var Thread[TArg]; tp: proc (arg: TArg) {.thread, nimcall.};
|
|
param: TArg)</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">handle
|
|
<li><a class="reference" href="#handle%2CThread%5BTArg%5D" title="handle[TArg](t: Thread[TArg]): SysThread">handle[TArg](t: Thread[TArg]): SysThread</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">joinThread
|
|
<li><a class="reference" href="#joinThread%2CThread%5BTArg%5D" title="joinThread[TArg](t: Thread[TArg])">joinThread[TArg](t: Thread[TArg])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">joinThreads
|
|
<li><a class="reference" href="#joinThreads%2Cvarargs%5BThread%5BTArg%5D%5D" title="joinThreads[TArg](t: varargs[Thread[TArg]])">joinThreads[TArg](t: varargs[Thread[TArg]])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">pinToCpu
|
|
<li><a class="reference" href="#pinToCpu%2CThread%5BArg%5D%2CNatural" title="pinToCpu[Arg](t: var Thread[Arg]; cpu: Natural)">pinToCpu[Arg](t: var Thread[Arg]; cpu: Natural)</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">running
|
|
<li><a class="reference" href="#running%2CThread%5BTArg%5D" title="running[TArg](t: Thread[TArg]): bool">running[TArg](t: Thread[TArg]): bool</a></li>
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
<li>
|
|
<a class="reference reference-toplevel" href="#19" id="69">Exports</a>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
<div class="nine columns" id="content">
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L1" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
<div id="tocRoot"></div>
|
|
|
|
<p class="module-desc"><p>Thread support for Nim. Threads allow multiple functions to execute concurrently.</p>
|
|
<p>In Nim, threads are a low-level construct and using a library like <tt class="docutils literal"><span class="pre"><span class="Identifier">malebolgia</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">taskpools</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">weave</span></span></tt> is recommended.</p>
|
|
<p>When creating a thread, you can pass arguments to it. As Nim's garbage collector does not use atomic references, sharing <tt class="docutils literal"><span class="pre"><span class="Keyword">ref</span></span></tt> and other variables managed by the garbage collector between threads is not supported. Use global variables to do so, or pointers.</p>
|
|
<p>Memory allocated using <a class="reference external" href="./system.html#allocShared.t%2CNatural">`sharedAlloc`</a> can be used and shared between threads.</p>
|
|
<p>To communicate between threads, consider using <a class="reference external" href="./system.html#Channel">channels</a></p>
|
|
|
|
<h1><a class="toc-backref" id="examples" href="#examples">Examples</a></h1><p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">locks</span>
|
|
|
|
<span class="Keyword">var</span>
|
|
<span class="Identifier">thr</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="Identifier">Thread</span><span class="Punctuation">[</span><span class="Keyword">tuple</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="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">]</span><span class="Punctuation">]</span>
|
|
<span class="Identifier">L</span><span class="Punctuation">:</span> <span class="Identifier">Lock</span>
|
|
|
|
<span class="Keyword">proc</span> <span class="Identifier">threadFunc</span><span class="Punctuation">(</span><span class="Identifier">interval</span><span class="Punctuation">:</span> <span class="Keyword">tuple</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="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">thread</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
|
|
<span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="Identifier">interval</span><span class="Operator">.</span><span class="Identifier">a</span><span class="Operator">..</span><span class="Identifier">interval</span><span class="Operator">.</span><span class="Identifier">b</span><span class="Punctuation">:</span>
|
|
<span class="Identifier">acquire</span><span class="Punctuation">(</span><span class="Identifier">L</span><span class="Punctuation">)</span> <span class="Comment"># lock stdout</span>
|
|
<span class="Identifier">echo</span> <span class="Identifier">i</span>
|
|
<span class="Identifier">release</span><span class="Punctuation">(</span><span class="Identifier">L</span><span class="Punctuation">)</span>
|
|
|
|
<span class="Identifier">initLock</span><span class="Punctuation">(</span><span class="Identifier">L</span><span class="Punctuation">)</span>
|
|
|
|
<span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="FloatNumber">0.</span><span class="Operator">.</span><span class="Identifier">high</span><span class="Punctuation">(</span><span class="Identifier">thr</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
|
|
<span class="Identifier">createThread</span><span class="Punctuation">(</span><span class="Identifier">thr</span><span class="Punctuation">[</span><span class="Identifier">i</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Identifier">threadFunc</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="Identifier">i</span><span class="Operator">*</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="Identifier">i</span><span class="Operator">*</span><span class="DecNumber">10</span><span class="Operator">+</span><span class="DecNumber">5</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">joinThreads</span><span class="Punctuation">(</span><span class="Identifier">thr</span><span class="Punctuation">)</span>
|
|
|
|
<span class="Identifier">deinitLock</span><span class="Punctuation">(</span><span class="Identifier">L</span><span class="Punctuation">)</span></pre></p>
|
|
<p>When using a memory management strategy that supports shared heaps like <tt class="docutils literal"><span class="pre"><span class="Identifier">arc</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">boehm</span></span></tt>, you can pass pointer to threads and share memory between them, but the memory must outlive the thread. The default memory management strategy, <tt class="docutils literal"><span class="pre"><span class="Identifier">orc</span></span></tt>, supports this. The example below is <strong>not valid</strong> for memory management strategies that use local heaps like <tt class="docutils literal"><span class="pre"><span class="Identifier">refc</span></span></tt>!</p>
|
|
<p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">locks</span>
|
|
|
|
<span class="Keyword">var</span> <span class="Identifier">l</span><span class="Punctuation">:</span> <span class="Identifier">Lock</span>
|
|
|
|
<span class="Keyword">proc</span> <span class="Identifier">threadFunc</span><span class="Punctuation">(</span><span class="Identifier">obj</span><span class="Punctuation">:</span> <span class="Keyword">ptr</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">thread</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
|
|
<span class="Identifier">withLock</span> <span class="Identifier">l</span><span class="Punctuation">:</span>
|
|
<span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="FloatNumber">0.</span><span class="Operator">.<</span><span class="DecNumber">100</span><span class="Punctuation">:</span>
|
|
<span class="Identifier">obj</span><span class="Punctuation">[</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">obj</span><span class="Punctuation">[</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">*</span> <span class="Identifier">obj</span><span class="Punctuation">[</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">len</span><span class="Punctuation">)</span>
|
|
|
|
<span class="Keyword">proc</span> <span class="Identifier">threadHandler</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">=</span>
|
|
<span class="Keyword">var</span> <span class="Identifier">thr</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="Identifier">Thread</span><span class="Punctuation">[</span><span class="Keyword">ptr</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">]</span><span class="Punctuation">]</span>
|
|
<span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">newSeq</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
|
|
|
|
<span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="FloatNumber">0.</span><span class="Operator">.</span><span class="Identifier">high</span><span class="Punctuation">(</span><span class="Identifier">thr</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
|
|
<span class="Identifier">createThread</span><span class="Punctuation">(</span><span class="Identifier">thr</span><span class="Punctuation">[</span><span class="Identifier">i</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Identifier">threadFunc</span><span class="Punctuation">,</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Keyword">addr</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">joinThreads</span><span class="Punctuation">(</span><span class="Identifier">thr</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">echo</span> <span class="Identifier">s</span>
|
|
|
|
<span class="Identifier">initLock</span><span class="Punctuation">(</span><span class="Identifier">l</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">threadHandler</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">deinitLock</span><span class="Punctuation">(</span><span class="Identifier">l</span><span class="Punctuation">)</span></pre> </p>
|
|
</p>
|
|
<div class="section" id="6">
|
|
<h1><a class="toc-backref" href="#6">Imports</a></h1>
|
|
<dl class="item">
|
|
<a class="reference external" href="threadtypes.html">threadtypes</a>, <a class="reference external" href="ansi_c.html">ansi_c</a>, <a class="reference external" href="assertions.html">assertions</a>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="12">
|
|
<h1><a class="toc-backref" href="#12">Procs</a></h1>
|
|
<dl class="item">
|
|
<div id="createThread-procs-all">
|
|
<div id="createThread,Thread[void],proc)">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#createThread%2CThread%5Bvoid%5D%2Cproc%29"><span class="Identifier">createThread</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">tp</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Other">)</span> {.<span class="Identifier">thread</span><span class="Other">,</span> <span class="Identifier">nimcall</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="Identifier">ResourceExhaustedError</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>
|
|
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L303" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L303" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="createThread,Thread[TArg],proc(TArg),TArg">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#createThread%2CThread%5BTArg%5D%2Cproc%28TArg%29%2CTArg"><span class="Identifier">createThread</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">;</span>
|
|
<span class="Identifier">tp</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">arg</span><span class="Other">:</span> <span class="Identifier">TArg</span><span class="Other">)</span> {.<span class="Identifier">thread</span><span class="Other">,</span> <span class="Identifier">nimcall</span>.}<span class="Other">;</span> <span class="Identifier">param</span><span class="Other">:</span> <span class="Identifier">TArg</span><span class="Other">)</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Creates a new thread <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> and starts its execution.</p>
|
|
<p>Entry point is the proc <tt class="docutils literal"><span class="pre"><span class="Identifier">tp</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">param</span></span></tt> is passed to <tt class="docutils literal"><span class="pre"><span class="Identifier">tp</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">TArg</span></span></tt> can be <tt class="docutils literal"><span class="pre"><span class="Identifier">void</span></span></tt> if you don't need to pass any data to the thread.</p>
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L261" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L261" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="handle-procs-all">
|
|
<div id="handle,Thread[TArg]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#handle%2CThread%5BTArg%5D"><span class="Identifier">handle</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="threadtypes.html#SysThread"><span class="Identifier">SysThread</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Returns the thread handle of <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L156" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L156" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="joinThread-procs-all">
|
|
<div id="joinThread,Thread[TArg]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#joinThread%2CThread%5BTArg%5D"><span class="Identifier">joinThread</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Waits for the thread <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> to finish.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L187" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L187" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="joinThreads-procs-all">
|
|
<div id="joinThreads,varargs[Thread[TArg]]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#joinThreads%2Cvarargs%5BThread%5BTArg%5D%5D"><span class="Identifier">joinThreads</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
|
|
<dd>
|
|
|
|
Waits for every thread in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> to finish.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L191" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L191" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="pinToCpu-procs-all">
|
|
<div id="pinToCpu,Thread[Arg],Natural">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#pinToCpu%2CThread%5BArg%5D%2CNatural"><span class="Identifier">pinToCpu</span></a><span class="Other">[</span><span class="Identifier">Arg</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a><span class="Other">[</span><span class="Identifier">Arg</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">cpu</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Pins a thread to a <span id="cpu_1">CPU</span>.</p>
|
|
<p>In other words sets a thread's <span id="affinity_1">affinity</span>. If you don't know what this means, you shouldn't use this proc.</p>
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L292" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L292" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="running-procs-all">
|
|
<div id="running,Thread[TArg]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#running%2CThread%5BTArg%5D"><span class="Identifier">running</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a><span class="Other">[</span><span class="Identifier">TArg</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> is running.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/typedthreads.nim#L152" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/typedthreads.nim#L152" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="19">
|
|
<h1><a class="toc-backref" href="#19">Exports</a></h1>
|
|
<dl class="item">
|
|
<a href="threadtypes.html#Thread"><span class="Identifier">Thread</span></a>
|
|
</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-12-25 20:13:50 UTC</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
|
|
|
|
</body>
|
|
</html>
|