Message passing 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
TChannel*[TMsg] = TInbox
- a channel for thread communication
TChannelId*[TMsg] = ptr TChannel[TMsg]
- the current implementation uses a pointer as a channel ID.
Procs
proc send*[TMsg](receiver: var TThread[TMsg], msg: TMsg)
- sends a message to a thread. msg is deeply copied.
proc send*[TMsg](receiver: TThreadId[TMsg], msg: TMsg)
- sends a message to a thread. msg is deeply copied.
proc recv*[TMsg](): TMsg
- receives a message from its internal message queue. This blocks until a message has arrived! You may use peek to avoid the blocking.
proc peek*(): int
- returns the current number of messages in the inbox.
proc peek*[TMsg](t: var TThread[TMsg]): int
- returns the current number of messages in the inbox of thread t.
proc ready*[TMsg](t: var TThread[TMsg]): bool
- returns true iff the thread t is waiting on recv for new messages.
proc open*[TMsg](c: var TChannel[TMsg])
- opens a channel c for inter thread communication.
proc close*[TMsg](c: var TChannel[TMsg])
- closes a channel c and frees its associated resources.
proc channelId*[TMsg](c: var TChannel[TMsg]): TChannelId[TMsg]
- returns the channel ID of c.
proc send*[TMsg](c: var TChannel[TMsg], msg: TMsg)
- sends a message to a channel. msg is deeply copied.
proc send*[TMsg](c: TChannelId[TMsg], msg: TMsg)
- sends a message to a thread. msg is deeply copied.
proc peek*[TMsg](c: var TChannel[TMsg]): int
- returns the current number of messages in the channel c.
proc peek*[TMsg](c: TChannelId[TMsg]): int
- returns the current number of messages in the channel c.
proc recv*[TMsg](c: TChannelId[TMsg]): TMsg
- receives a message from the channel c. This blocks until a message has arrived! You may use peek to avoid the blocking.
proc recv*[TMsg](c: var TChannel[TMsg]): TMsg
- receives a message from the channel c. This blocks until a message has arrived! You may use peek to avoid the blocking.