Debian Codegraph @

doc/hpc/chap9.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
7 <head>
8 <title>GAP (hpc) - Chapter 9: Synchronization variables</title>
9 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10 <meta name="generator" content="GAPDoc2HTML" />
11 <link rel="stylesheet" type="text/css" href="manual.css" />
12 <script src="manual.js" type="text/javascript"></script>
13 <script type="text/javascript">overwriteStyle();</script>
14 </head>
15 <body class="chap9" onload="jscontent()">
16
17
18 <div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chapInd.html">Ind</a> </div>
19
20 <div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap8.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap10.html">[Next Chapter]</a>&nbsp; </div>
21
22 <p id="mathjaxlink" class="pcenter"><a href="chap9_mj.html">[MathJax on]</a></p>
23 <p><a id="X84583568784B622A" name="X84583568784B622A"></a></p>
24 <div class="ChapSects"><a href="chap9.html#X84583568784B622A">9 <span class="Heading">Synchronization variables</span></a>
25 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap9.html#X84583568784B622A">9.1 <span class="Heading">Synchronization variables</span></a>
26 </span>
27 <div class="ContSSBlock">
28 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap9.html#X7B55EA0E8672087C">9.1-1 CreateSyncVar</a></span>
29 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap9.html#X85E910BF7BBF3270">9.1-2 SyncWrite</a></span>
30 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap9.html#X7B42B29B8441B4F5">9.1-3 SyncRead</a></span>
31 </div></div>
32 </div>
33
34 <h3>9 <span class="Heading">Synchronization variables</span></h3>
35
36 <p><a id="X84583568784B622A" name="X84583568784B622A"></a></p>
37
38 <h4>9.1 <span class="Heading">Synchronization variables</span></h4>
39
40 <p>Synchronization variables (also often called dataflow variables in the literature) are variables that can be written only once; attempts to read the variable block until it has been written to.</p>
41
42 <p>Synchronization variables are created with <code class="func">CreateSyncVar</code> (<a href="chap9.html#X7B55EA0E8672087C"><span class="RefLink">9.1-1</span></a>), written with <code class="func">SyncWrite</code> (<a href="chap9.html#X85E910BF7BBF3270"><span class="RefLink">9.1-2</span></a>) and read with <code class="func">SyncRead</code> (<a href="chap9.html#X7B42B29B8441B4F5"><span class="RefLink">9.1-3</span></a>).</p>
43
44
45 <div class="example"><pre>
46 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">sv := CreateSyncVar();;</span>
47 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RunAsyncTask(function()</span>
48 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> Sleep(10);</span>
49 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> SyncWrite(sv, MakeImmutable([1, 2, 3]));</span>
50 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> end);;</span>
51 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SyncRead(sv);</span>
52 [ 1, 2, 3 ]
53 </pre></div>
54
55 <p><a id="X7B55EA0E8672087C" name="X7B55EA0E8672087C"></a></p>
56
57 <h5>9.1-1 CreateSyncVar</h5>
58
59 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CreateSyncVar</code>( )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
60 <p>The function <code class="func">CreateSyncVar</code> takes no arguments. It returns a new synchronization variable. There is no need to deallocate it; the garbage collector will free the memory and all related resources when it is no longer accessible.</p>
61
62 <p><a id="X85E910BF7BBF3270" name="X85E910BF7BBF3270"></a></p>
63
64 <h5>9.1-2 SyncWrite</h5>
65
66 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SyncWrite</code>( <var class="Arg">syncvar</var>, <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
67 <p><code class="func">SyncWrite</code> attempts to assign the value <var class="Arg">obj</var> to <var class="Arg">syncvar</var>. If <var class="Arg">syncvar</var> has been previously assigned a value, the call will fail with a runtime error; otherwise, <var class="Arg">obj</var> will be assigned to <var class="Arg">syncvar</var>.</p>
68
69 <p>In order to make sure that the recipient can read the result, the <var class="Arg">obj</var> argument should not be a thread-local object; it should be public, read-only, or shared.</p>
70
71 <p><a id="X7B42B29B8441B4F5" name="X7B42B29B8441B4F5"></a></p>
72
73 <h5>9.1-3 SyncRead</h5>
74
75 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SyncRead</code>( <var class="Arg">syncvar</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
76 <p><code class="func">SyncRead</code> reads the value previously assigned to <var class="Arg">syncvar</var> with <code class="func">SyncWrite</code> (<a href="chap9.html#X85E910BF7BBF3270"><span class="RefLink">9.1-2</span></a>). If no value has been assigned yet, it blocks. It returns the assigned value.</p>
77
78
79 <div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap8.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap10.html">[Next Chapter]</a>&nbsp; </div>
80
81
82 <div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chapInd.html">Ind</a> </div>
83
84 <hr />
85 <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
86 </body>
87 </html>