| 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 | <script type="text/javascript" |
| 9 | src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> |
| 10 | </script> |
| 11 | <title>GAP (hpc) - Chapter 9: Synchronization variables</title> |
| 12 | <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> |
| 13 | <meta name="generator" content="GAPDoc2HTML" /> |
| 14 | <link rel="stylesheet" type="text/css" href="manual.css" /> |
| 15 | <script src="manual.js" type="text/javascript"></script> |
| 16 | <script type="text/javascript">overwriteStyle();</script> |
| 17 | </head> |
| 18 | <body class="chap9" onload="jscontent()"> |
| 19 | |
| 20 | |
| 21 | <div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a> <a href="chap1_mj.html">1</a> <a href="chap2_mj.html">2</a> <a href="chap3_mj.html">3</a> <a href="chap4_mj.html">4</a> <a href="chap5_mj.html">5</a> <a href="chap6_mj.html">6</a> <a href="chap7_mj.html">7</a> <a href="chap8_mj.html">8</a> <a href="chap9_mj.html">9</a> <a href="chap10_mj.html">10</a> <a href="chap11_mj.html">11</a> <a href="chapInd_mj.html">Ind</a> </div> |
| 22 | |
| 23 | <div class="chlinkprevnexttop"> <a href="chap0_mj.html">[Top of Book]</a> <a href="chap0_mj.html#contents">[Contents]</a> <a href="chap8_mj.html">[Previous Chapter]</a> <a href="chap10_mj.html">[Next Chapter]</a> </div> |
| 24 | |
| 25 | <p id="mathjaxlink" class="pcenter"><a href="chap9.html">[MathJax off]</a></p> |
| 26 | <p><a id="X84583568784B622A" name="X84583568784B622A"></a></p> |
| 27 | <div class="ChapSects"><a href="chap9_mj.html#X84583568784B622A">9 <span class="Heading">Synchronization variables</span></a> |
| 28 | <div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap9_mj.html#X84583568784B622A">9.1 <span class="Heading">Synchronization variables</span></a> |
| 29 | </span> |
| 30 | <div class="ContSSBlock"> |
| 31 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap9_mj.html#X7B55EA0E8672087C">9.1-1 CreateSyncVar</a></span> |
| 32 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap9_mj.html#X85E910BF7BBF3270">9.1-2 SyncWrite</a></span> |
| 33 | <span class="ContSS"><br /><span class="nocss"> </span><a href="chap9_mj.html#X7B42B29B8441B4F5">9.1-3 SyncRead</a></span> |
| 34 | </div></div> |
| 35 | </div> |
| 36 | |
| 37 | <h3>9 <span class="Heading">Synchronization variables</span></h3> |
| 38 | |
| 39 | <p><a id="X84583568784B622A" name="X84583568784B622A"></a></p> |
| 40 | |
| 41 | <h4>9.1 <span class="Heading">Synchronization variables</span></h4> |
| 42 | |
| 43 | <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> |
| 44 | |
| 45 | <p>Synchronization variables are created with <code class="func">CreateSyncVar</code> (<a href="chap9_mj.html#X7B55EA0E8672087C"><span class="RefLink">9.1-1</span></a>), written with <code class="func">SyncWrite</code> (<a href="chap9_mj.html#X85E910BF7BBF3270"><span class="RefLink">9.1-2</span></a>) and read with <code class="func">SyncRead</code> (<a href="chap9_mj.html#X7B42B29B8441B4F5"><span class="RefLink">9.1-3</span></a>).</p> |
| 46 | |
| 47 | |
| 48 | <div class="example"><pre> |
| 49 | <span class="GAPprompt">gap></span> <span class="GAPinput">sv := CreateSyncVar();;</span> |
| 50 | <span class="GAPprompt">gap></span> <span class="GAPinput">RunAsyncTask(function()</span> |
| 51 | <span class="GAPprompt">></span> <span class="GAPinput"> Sleep(10);</span> |
| 52 | <span class="GAPprompt">></span> <span class="GAPinput"> SyncWrite(sv, MakeImmutable([1, 2, 3]));</span> |
| 53 | <span class="GAPprompt">></span> <span class="GAPinput"> end);;</span> |
| 54 | <span class="GAPprompt">gap></span> <span class="GAPinput">SyncRead(sv);</span> |
| 55 | [ 1, 2, 3 ] |
| 56 | </pre></div> |
| 57 | |
| 58 | <p><a id="X7B55EA0E8672087C" name="X7B55EA0E8672087C"></a></p> |
| 59 | |
| 60 | <h5>9.1-1 CreateSyncVar</h5> |
| 61 | |
| 62 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CreateSyncVar</code>( )</td><td class="tdright">( function )</td></tr></table></div> |
| 63 | <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> |
| 64 | |
| 65 | <p><a id="X85E910BF7BBF3270" name="X85E910BF7BBF3270"></a></p> |
| 66 | |
| 67 | <h5>9.1-2 SyncWrite</h5> |
| 68 | |
| 69 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SyncWrite</code>( <var class="Arg">syncvar</var>, <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div> |
| 70 | <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> |
| 71 | |
| 72 | <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> |
| 73 | |
| 74 | <p><a id="X7B42B29B8441B4F5" name="X7B42B29B8441B4F5"></a></p> |
| 75 | |
| 76 | <h5>9.1-3 SyncRead</h5> |
| 77 | |
| 78 | <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SyncRead</code>( <var class="Arg">syncvar</var> )</td><td class="tdright">( function )</td></tr></table></div> |
| 79 | <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_mj.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> |
| 80 | |
| 81 | |
| 82 | <div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of Book]</a> <a href="chap0_mj.html#contents">[Contents]</a> <a href="chap8_mj.html">[Previous Chapter]</a> <a href="chap10_mj.html">[Next Chapter]</a> </div> |
| 83 | |
| 84 | |
| 85 | <div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a> <a href="chap1_mj.html">1</a> <a href="chap2_mj.html">2</a> <a href="chap3_mj.html">3</a> <a href="chap4_mj.html">4</a> <a href="chap5_mj.html">5</a> <a href="chap6_mj.html">6</a> <a href="chap7_mj.html">7</a> <a href="chap8_mj.html">8</a> <a href="chap9_mj.html">9</a> <a href="chap10_mj.html">10</a> <a href="chap11_mj.html">11</a> <a href="chapInd_mj.html">Ind</a> </div> |
| 86 | |
| 87 | <hr /> |
| 88 | <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p> |
| 89 | </body> |
| 90 | </html> |