<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>
<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.html#X81DFC84779CD1C1E"><span class="RefLink">6.1-2</span></a>) function.</p>
<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>
<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>
<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="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.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>
<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="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.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.
<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.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.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.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>
<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.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>
<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="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.html#X8521A5777CCD0B37"><span class="RefLink">6.1-8</span></a>) and <code class="func">SetInterruptHandler</code> (<a href="chap6.html#X80C207B387CA888E"><span class="RefLink">6.1-9</span></a>).</p>
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.