Module channels

Channel support for threads. Note: This is part of the system module. Do not import it directly. To activate thread support you need to compile with the --threads:on command line switch.

Note: The current implementation of message passing is slow and does not work with cyclic data structures.

Types

Channel* {.gcsafe.}[TMsg] = RawChannel
a channel for thread communication   Source

Procs

proc send*[TMsg](c: var Channel[TMsg]; msg: TMsg)
sends a message to a thread. msg is deeply copied.   Source
proc recv*[TMsg](c: var Channel[TMsg]): TMsg
receives a message from the channel c. This blocks until a message has arrived! You may use peek to avoid the blocking.   Source
proc tryRecv*[TMsg](c: var Channel[TMsg]): tuple[dataAvailable: bool, msg: TMsg]
try to receives a message from the channel c if available. Otherwise it returns (false, default(msg)).   Source
proc peek*[TMsg](c: var Channel[TMsg]): int
returns the current number of messages in the channel c. Returns -1 if the channel has been closed. Note: This is dangerous to use as it encourages races. It's much better to use tryRecv instead.   Source
proc open*[TMsg](c: var Channel[TMsg])
opens a channel c for inter thread communication.   Source
proc close*[TMsg](c: var Channel[TMsg])
closes a channel c and frees its associated resources.   Source
proc ready*[TMsg](c: var Channel[TMsg]): bool
returns true iff some thread is waiting on the channel c for new messages.   Source