Next: control.future
- Futures, Previous: compat.real-elementary-functions
- Backward-compatible real elementary functions, Up: Library modules - Utilities [Contents][Index]
control.cseq
- Concurrent sequencesConcurrent sequence (cseq) is a lazy sequence (see Lazy sequences), but the generator runs in a separate thread. You can use producer-consumer pararellism very easily using cseq; from the consumer side, it just looks like an ordinary list. Synchornization is implicitly taken care of.
Internally, it uses mtqueue (see data.queue
- Queue) for synchronization.
{control.cseq}
Create a lazy sequence from generator, much like generator->lseq
,
except that gen runs in a separate thread.
The returend value looks like an ordinary list, but its cdrs are computed in parallel. If a cdr isn’t computed yet, the reader thread waits until a value becomes available. The generator gen can be called to generate values asynchronously, until the internal queue gets full. (Compare this to an ordinary lseq, in which gen is called when it is required, and it runs in the same thread as the caller.)
If gen raises an error, it is caught, and reraised when the consumer reads to the point when gen raised the error.
The optional queue-length must be a nonnegative exact integer or #f
.
If it is an integer, it specifies the length of the internal queue.
If it is #f
, an appropriate value is selected by the library
(currently 64).
Note that Gauche’s lseq read-ahead one item (see Lazy sequences). So even if you set the queue length to 0, gen is called before the consumer reads out any value.
{control.cseq}
Returns an lseq, whose value is generated in proc, which is called
in a separate thread. (See also coroutine->lseq
,
Lazy sequence constructors).
The proc argument is a procedure to be called with one argument,
yield. The yield argument is a procedure, and whenever it is
called with a value, that value becomes the next item of the resulting lseq.
When proc returns, it becomes the end of the lseq.
If proc raises an error, it is caught, and reraised when the consumer reads to the point when previously generated values are all read and next value is about to read.
The optional queue-length must be a nonnegative exact integer or #f
.
If it is an integer, it specifies the length of the internal queue.
If it is #f
, an appropriate value is selected by the library
(currently 64).
Next: control.future
- Futures, Previous: compat.real-elementary-functions
- Backward-compatible real elementary functions, Up: Library modules - Utilities [Contents][Index]