Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  chap6_mj.html   Sprache: HTML

 
 products/sources/formale Sprachen/GAP/doc/hpc/chap6_mj.html


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<title>GAP (hpc) - Chapter 6: Thread functions</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap6"  onload="jscontent()">


<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>

<div class="chlinkprevnexttop"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap5_mj.html">[Previous Chapter]</a>    <a href="chap7_mj.html">[Next Chapter]</a>   </div>

<p id="mathjaxlink" class="pcenter"><a href="chap6.html">[MathJax off]</a></p>
<p><a id="X841085357B854E1C" name="X841085357B854E1C"></a></p>
<div class="ChapSects"><a href="chap6_mj.html#X841085357B854E1C">6 <span class="Heading">Thread functions</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap6_mj.html#X841085357B854E1C">6.1 <span class="Heading">Thread functions</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X7A541B6C84980B7D">6.1-1 CreateThread</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X81DFC84779CD1C1E">6.1-2 WaitThread</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X7982BA8D782C171B">6.1-3 CurrentThread</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X80FA498D866028CB">6.1-4 ThreadID</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X787679BC7D36FAA3">6.1-5 KillThread</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X7BC284107E56A01B">6.1-6 PauseThread</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X80D590EC78C93F94">6.1-7 ResumeThread</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X8521A5777CCD0B37">6.1-8 InterruptThread</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X80C207B387CA888E">6.1-9 SetInterruptHandler</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X78E5F5987BEFACE6">6.1-10 NewInterruptID</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap6_mj.html#X863799F07D55BAE0">6.1-11 MAX_INTERRUPT</a></span>
</div></div>
</div>

<h3>6 <span class="Heading">Thread functions</span></h3>

<p>HPC-GAP has low-level functionality to support explicit creation of threads. In practice, programmers should use higher-level functionality, such as tasks, to describe concurrency. The thread functions described here exist to facilitate the construction of higher level libraries and are not meant to be used directly.</p>

<p><a id="X841085357B854E1C" name="X841085357B854E1C"></a></p>

<h4>6.1 <span class="Heading">Thread functions</span></h4>

<p><a id="X7A541B6C84980B7D" name="X7A541B6C84980B7D"></a></p>

<h5>6.1-1 CreateThread</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CreateThread</code>( <var class="Arg">func</var>[, <var class="Arg">arg1</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>New threads are created with the function <code class="func">CreateThread</code>. The thread takes at least one function as its argument that it will call in the newly created thread; it also accepts zero or more parameters that will be passed to that function.</p>

<p>The function returns a thread object describing the thread.</p>

<p>Only a finite number of threads can be active at a time (that limit is system-dependent). To reclaim the resources occupied by one thread, use the <code class="func">WaitThread</code> (<a href="chap6_mj.html#X81DFC84779CD1C1E"><span class="RefLink">6.1-2</span></a>) function.</p>

<p><a id="X81DFC84779CD1C1E" name="X81DFC84779CD1C1E"></a></p>

<h5>6.1-2 WaitThread</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WaitThread</code>( <var class="Arg">threadID</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">WaitThread</code> function waits for the thread identified by <var class="Arg">threadID</var> to finish; it does not return any value. When it returns, it returns all resources occupied by the thread it waited for, such as thread-local memory and operating system structures, to the system.</p>

<p><a id="X7982BA8D782C171B" name="X7982BA8D782C171B"></a></p>

<h5>6.1-3 CurrentThread</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CurrentThread</code>(  )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">CurrentThread</code> function returns the thread object for the current thread.</p>

<p><a id="X80FA498D866028CB" name="X80FA498D866028CB"></a></p>

<h5>6.1-4 ThreadID</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ThreadID</code>( <var class="Arg">thread</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">ThreadID</code> function returns a numeric thread id for the given thread. The thread id of the main thread is always 0.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">CurrentThread();</span>
<thread #0: running>
<span class="GAPprompt">gap></span> <span class="GAPinput">ThreadID(CurrentThread());</span>
0
</pre></div>

<p><a id="X787679BC7D36FAA3" name="X787679BC7D36FAA3"></a></p>

<h5>6.1-5 KillThread</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ KillThread</code>( <var class="Arg">thread</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">KillThread</code> function terminates the given thread. Any region locks that the thread currently holds will be unlocked. The thread can be specified as a thread object or via its numeric id.</p>

<p>The implementation for <code class="func">KillThread</code> is dependent on the interpreter actually executing statements. Threads performing system calls, for example, will not be terminated until the system call returns. Similarly, long-running kernel functions will delay termination until the kernel function returns.</p>

<p>Use of <code class="code">CALL_WITH_CATCH</code> will not prevent a thread from being terminated. If you wish to make sure that catch handlers will be visited, use <code class="func">InterruptThread</code> (<a href="chap6_mj.html#X8521A5777CCD0B37"><span class="RefLink">6.1-8</span></a>) instead. <code class="func">KillThread</code> should be used for threads that cannot be controlled anymore in any other way but still eat system resources.</p>

<p><a id="X7BC284107E56A01B" name="X7BC284107E56A01B"></a></p>

<h5>6.1-6 PauseThread</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PauseThread</code>( <var class="Arg">thread</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">PauseThread</code> function suspends execution for the given thread. The thread can be specified as a thread object or via its numeric id.</p>

<p>The implementation for <code class="func">PauseThread</code> is dependent on the interpreter actually executing statements. Threads performing system calls, for example, will not pause until the system call returns. Similarly, long-running kernel functions will not pause until the kernel function returns.</p>

<p>While a thread is paused, the thread that initiated the pause can access the paused thread's thread-local region.




<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">loop := function() while true do Sleep(1); od; end;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">x := fail;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">th := CreateThread(function() x := [1, 2, 3]; loop(); end);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">PauseThread(th);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">x;</span>
[ 1, 2, 3 ]
</pre></div>

<p><a id="X80D590EC78C93F94" name="X80D590EC78C93F94"></a></p>

<h5>6.1-7 ResumeThread</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ResumeThread</code>( <var class="Arg">thread</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">ResumeThread</code> function resumes execution for the given thread that was paused with <code class="func">PauseThread</code> (<a href="chap6_mj.html#X7BC284107E56A01B"><span class="RefLink">6.1-6</span></a>). The thread can be specified as a thread object or via its numeric id.</p>

<p>If the thread isn't paused, ResumeThread is a no-op.



<p><a id="X8521A5777CCD0B37" name="X8521A5777CCD0B37"></a></p>

<h5>6.1-8 InterruptThread</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ InterruptThread</code>( <var class="Arg">thread</var>, <var class="Arg">interrupt</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">InterruptThread</code> function calls an interrupt handler for the given thread. The thread can be specified as a thread object or via its numeric id. The interrupt is specified as an integer between 0 and <code class="func">MAX_INTERRUPT</code> (<a href="chap6_mj.html#X863799F07D55BAE0"><span class="RefLink">6.1-11</span></a>).</p>

<p>An interrupt number of zero (or an interrupt number for which no interrupt handler has been set up with <code class="func">SetInterruptHandler</code> (<a href="chap6_mj.html#X80C207B387CA888E"><span class="RefLink">6.1-9</span></a>) will cause the thread to enter a break loop. Otherwise, the respective interrupt handler that has been created with <code class="func">SetInterruptHandler</code> (<a href="chap6_mj.html#X80C207B387CA888E"><span class="RefLink">6.1-9</span></a>) will be called.</p>

<p>The implementation for <code class="func">InterruptThread</code> is dependent on the interpreter actually executing statements. Threads performing system calls, for example, will not call interrupt handlers until the system call returns. Similarly, long-running kernel functions will delay invocation of the interrupt handler until the kernel function returns.</p>

<p><a id="X80C207B387CA888E" name="X80C207B387CA888E"></a></p>

<h5>6.1-9 SetInterruptHandler</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SetInterruptHandler</code>( <var class="Arg">interrupt</var>, <var class="Arg">handler</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">SetInterruptHandler</code> function allows the programmer to set up interrupt handlers for the current thread. The interrupt number must be in the range from 1 to <code class="func">MAX_INTERRUPT</code> (<a href="chap6_mj.html#X863799F07D55BAE0"><span class="RefLink">6.1-11</span></a>) (inclusive); the handler must be a parameterless function (or <code class="keyw">fail</code> to remove a handler).</p>

<p><a id="X78E5F5987BEFACE6" name="X78E5F5987BEFACE6"></a></p>

<h5>6.1-10 NewInterruptID</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NewInterruptID</code>(  )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">NewInterruptID</code> function returns a previously unused number (starting at 1). These numbers can be used to globally coordinate interrupt numbers.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">StopTaskInterrupt := NewInterruptID();</span>
1
<span class="GAPprompt">gap></span> <span class="GAPinput">SetInterruptHandler(StopTaskInterrupt, StopTaskHandler);</span>
</pre></div>

<p><a id="X863799F07D55BAE0" name="X863799F07D55BAE0"></a></p>

<h5>6.1-11 MAX_INTERRUPT</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ MAX_INTERRUPT</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>The global variable <code class="func">MAX_INTERRUPT</code> is an integer containing the maximum value for the interrupt arguments to <code class="func">InterruptThread</code> (<a href="chap6_mj.html#X8521A5777CCD0B37"><span class="RefLink">6.1-8</span></a>) and <code class="func">SetInterruptHandler</code> (<a href="chap6_mj.html#X80C207B387CA888E"><span class="RefLink">6.1-9</span></a>).</p>


<div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap5_mj.html">[Previous Chapter]</a>    <a href="chap7_mj.html">[Next Chapter]</a>   </div>


<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>

<hr />
<p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>

98%


¤ Dauer der Verarbeitung: 0.16 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge