<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CreateChannel</code>( [<var class="Arg">capacity</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">CreateChannel</code> returns a FIFO communication channel that can be used to exchange information between threads. Its optional argument is a capacity (positive integer). If insufficient resources are available to create a channel, it returns -1. If the capacity is not a positive integer, an error will be raised.</p>
<p>If a capacity is not provided, by default the channel can hold an indefinite number of objects. Otherwise, attempts to store objects in the channel beyond its capacity will block.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SendChannel</code>( <var class="Arg">channel</var>, <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">SendChannel</code> accepts two arguments, a channel object returned by <code class="func">CreateChannel</code> (<a href="chap7.html#X7E666A8B7C37ADA4"><span class="RefLink">7.1-1</span></a>), and an arbitrary GAP object. It stores <var class="Arg">obj</var> in <var class="Arg">channel</var>. If <var class="Arg">channel</var> has a finite capacity and is currently full, then <code class="func">SendChannel</code> will block until at least one element has been removed from the channel, e.g. using <code class="func">ReceiveChannel</code> (<a href="chap7.html#X7FEABC588101CCE7"><span class="RefLink">7.1-6</span></a>).</p>
<p><code class="func">SendChannel</code> performs automatic region migration for thread-local objects. If <var class="Arg">obj</var> is thread-local for the current thread, it will be migrated (along with all subobjects contained in the same region) to the receiving thread's thread-local data space. In between sending and receiving, obj cannot be accessed by either thread.
<p>This example demonstrates sending messages across a channel.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TransmitChannel</code>( <var class="Arg">channel</var>, <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TransmitChannel</code> is identical to <code class="func">SendChannel</code> (<a href="chap7.html#X81233BCB7B1173FA"><span class="RefLink">7.1-2</span></a>), except that it does not perform automatic region migration of thread-local objects.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TrySendChannel</code>( <var class="Arg">channel</var>, <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TrySendChannel</code> is identical to <code class="func">SendChannel</code> (<a href="chap7.html#X81233BCB7B1173FA"><span class="RefLink">7.1-2</span></a>), except that it returns if the channel is full instead of blocking. It returns true if the send was successful and false otherwise.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TryTransmitChannel</code>( <var class="Arg">channel</var>, <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TryTransmitChannel</code> is identical to <code class="func">TrySendChannel</code> (<a href="chap7.html#X7AEFF25D8143DA77"><span class="RefLink">7.1-4</span></a>), except that it does not perform automatic region migration of thread-local objects.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReceiveChannel</code>( <var class="Arg">channel</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ReceiveChannel</code> is used to retrieve elements from a channel. If <var class="Arg">channel</var> is empty, the call will block until an element has been added to the channel via <code class="func">SendChannel</code> (<a href="chap7.html#X81233BCB7B1173FA"><span class="RefLink">7.1-2</span></a>) or a similar primitive.</p>
<p>See <code class="func">SendChannel</code> (<a href="chap7.html#X81233BCB7B1173FA"><span class="RefLink">7.1-2</span></a>) for an example.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TryReceiveChannel</code>( <var class="Arg">channel</var>, <var class="Arg">default</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TryReceiveChannel</code>, like <code class="func">ReceiveChannel</code> (<a href="chap7.html#X7FEABC588101CCE7"><span class="RefLink">7.1-6</span></a>), attempts to retrieve an object from <var class="Arg">channel</var>. If it does not succeed, however, it will return <var class="Arg">default</var> rather than blocking.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ MultiSendChannel</code>( <var class="Arg">channel</var>, <var class="Arg">list</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">MultiSendChannel</code> allows the sending of all the objects contained in the list <var class="Arg">list</var> to <var class="Arg">channel</var> as a single operation. The list must be dense and is not modified by the call. The function will send elements starting at index 1 until all elements have been sent. If a channel with finite capacity is full, then the operation will block until all elements can be sent.</p>
<p>The operation is designed to be more efficient than sending all elements individually via <code class="func">SendChannel</code> (<a href="chap7.html#X81233BCB7B1173FA"><span class="RefLink">7.1-2</span></a>) by minimizing potentially expensive concurrency operations.</p>
<p>See <code class="func">MultiReceiveChannel</code> (<a href="chap7.html#X807D4263798D775E"><span class="RefLink">7.1-10</span></a>) for an example.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TryMultiSendChannel</code>( <var class="Arg">channel</var>, <var class="Arg">list</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TryMultiSendChannel</code> operates like <code class="func">MultiSendChannel</code> (<a href="chap7.html#X7A5E26F5799A17B4"><span class="RefLink">7.1-8</span></a>), except that it returns rather than blocking if it cannot send any more elements if the channel is full. It returns the number of elements it has sent. If <var class="Arg">channel</var> does not have finite capacity, <code class="func">TryMultiSendChannel</code> will always send all elements in the list.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ MultiReceiveChannel</code>( <var class="Arg">channel</var>, <var class="Arg">amount</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">MultiReceiveChannel</code> is the receiving counterpart to <code class="func">MultiSendChannel</code> (<a href="chap7.html#X7A5E26F5799A17B4"><span class="RefLink">7.1-8</span></a>).It will try to receive up to <var class="Arg">amount</var> objects from <var class="Arg">channel</var>. If the channel contains less than <var class="Arg">amount</var> objects, it will return rather than blocking.</p>
<p>The function returns a list of all the objects received.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReceiveAnyChannel</code>( <var class="Arg">channel_1</var>, <var class="Arg">...</var>, <var class="Arg">channel_n</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReceiveAnyChannel</code>( <var class="Arg">channel_list</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ReceiveAnyChannel</code> is a multiplexing variant of<code class="func">ReceiveChannel</code> (<a href="chap7.html#X7FEABC588101CCE7"><span class="RefLink">7.1-6</span></a>). It blocks until at least one of the channels provided contains an object. It will then retrieve that object from the channel and return it.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReceiveAnyChannelWithIndex</code>( <var class="Arg">channel_1</var>, <var class="Arg">...</var>, <var class="Arg">channel_n</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReceiveAnyChannelWithIndex</code>( <var class="Arg">channel_list</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ReceiveAnyChannelWithIndex</code> works like <code class="func">ReceiveAnyChannel</code> (<a href="chap7.html#X8355AFCC8530B2CA"><span class="RefLink">7.1-11</span></a>), except that it returns a list with two elements, the first being the object being received, the second being the number of the channel from which the object has been retrieved.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TallyChannel</code>( <var class="Arg">channel</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TallyChannel</code> returns the number of objects that a channel contains. This number can increase or decrease, as data is sent to or received from this channel. Send operations will only ever increase and receive operations will only ever decrease this count. Thus, if there is only one thread receiving data from the channel, it can use the result as a lower bound for the number of elements that will be available in the channel.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ InspectChannel</code>( <var class="Arg">channel</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">InspectChannel</code> returns a list of the objects that a channel contains. Note that objects that are not in the shared, public, or read-only region will be temporarily stored in the so-called limbo region while in transit and will be inaccessible through normal means until they have been received.</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.0.12Bemerkung:
¤
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.