diff --git a/atomics.html b/atomics.html index e3caa15..3396ec0 100644 --- a/atomics.html +++ b/atomics.html @@ -497,7 +497,7 @@

Procs

diff --git a/channels.html b/channels.html index 3815aa6..6669906 100644 --- a/channels.html +++ b/channels.html @@ -129,8 +129,11 @@

threading/channels

This module only works with --gc:arc or --gc:orc.

Warning: This module is experimental and its interface may change.
-

This module implements multi-producer multi-consumer channels - a concurrency primitive with a high-level interface intended for communication and synchronization between threads. It allows sending and receiving typed data, enabling safe and efficient concurrency.

-

The Chan type represents a generic channel object that internally manages the underlying resources and synchronization. It has to be initialized using the newChan proc. Sending and receiving operations are provided by the blocking send and recv procs, and non-blocking trySend and tryRecv procs.

+

This module implements multi-producer multi-consumer channels - a concurrency primitive with a high-level interface intended for communication and synchronization between threads. It allows sending and receiving typed, isolated data, enabling safe and efficient concurrency.

+

The Chan type represents a generic fixed-size channel object that internally manages the underlying resources and synchronization. It has to be initialized using the newChan proc. Sending and receiving operations are provided by the blocking send and recv procs, and non-blocking trySend and tryRecv procs. Send operations add messages to the channel, receiving operations remove them.

+

See also:

+

The following is a simple example of two different ways to use channels: blocking and non-blocking.

Example: cmd: --threads:on --gc:orc

@@ -202,8 +205,8 @@

Types

Typed channel - Source   -Edit   + Source   +Edit  
@@ -219,8 +222,8 @@

Procs

Shares Channel by reference counting. - Source   -Edit   + Source   +Edit  
@@ -232,8 +235,8 @@

Procs

- Source   -Edit   + Source   +Edit  
@@ -244,9 +247,11 @@

Procs

proc newChan[T](elements: Positive = 30): Chan[T]
- An initialization procedure, necessary for acquiring resources and initializing internal state of the channel. - Source   -Edit   +

An initialization procedure, necessary for acquiring resources and initializing internal state of the channel.

+

elements is the capacity of the channel and thus how many items it can hold before it refuses to accept any further items.

+ + Source   +Edit  
@@ -257,9 +262,9 @@

Procs

func peek[T](c: Chan[T]): int {.inline.}
- Returns an estimation of current number of items held by the channel. - Source   -Edit   + Returns an estimation of the current number of items held by the channel. + Source   +Edit  
@@ -270,9 +275,9 @@

Procs

proc recv[T](c: Chan[T]): T {.inline.}
- Receives item from the channel (blocking). - Source   -Edit   + Receives an item from the channel. A version of recv that returns the item. + Source   +Edit  
@@ -280,9 +285,11 @@

Procs

proc recv[T](c: Chan[T]; dst: var T) {.inline.}
- Receives item from the channel (blocking). - Source   -Edit   +

Receives an item from the channel. Fills dist with the item. This blocks the receiving thread until an item was successfully received.

+

If the channel does not contain any items this will block the thread until items get sent to the channel.

+ + Source   +Edit  
@@ -293,9 +300,9 @@

Procs

proc recvIso[T](c: Chan[T]): Isolated[T] {.inline.}
- - Source   -Edit   + Receives an item from the channel. A version of recv that returns the item and isolates it. + Source   +Edit  
@@ -306,9 +313,11 @@

Procs

proc send[T](c: Chan[T]; src: sink Isolated[T]) {.inline.}
- Sends item to the channel (blocking). - Source   -Edit   +

Sends item to the channel. This blocks the sending thread until the item was successfully sent.

+

If the channel is already full with items this will block the thread until items from the channel are removed.

+ + Source   +Edit  
@@ -319,9 +328,12 @@

Procs

proc tryRecv[T](c: Chan[T]; dst: var T): bool {.inline.}
- Receives item from the channel (non-blocking). - Source   -Edit   +

Tries to receive a message from the channel c and fill dst with its value. This returns immediately even if no message is found. Doesn't block.

+

This can fail for all sort of reasons, including a lack of messages in the channel to receive or contention.

+

If it fails it returns false. Otherwise it returns true.

+ + Source   +Edit  
@@ -332,9 +344,12 @@

Procs

proc trySend[T](c: Chan[T]; src: sink Isolated[T]): bool {.inline.}
- Sends item to the channel (non-blocking). - Source   -Edit   +

Tries to send a message to a channel.

+

The memory src is moved, not copied. Doesn't block.

+

Returns false if the message was not sent because the number of pending items in the channel exceeded its capacity.

+ + Source   +Edit  
@@ -352,8 +367,8 @@

Templates

Helper template for send. - Source   -Edit   + Source   +Edit  
@@ -364,9 +379,9 @@

Templates

template trySend[T](c: Chan[T]; src: T): bool
- Helper template for trySend. - Source   -Edit   + Helper template for trySend. + Source   +Edit  
@@ -382,7 +397,7 @@

Templates

diff --git a/channels.idx b/channels.idx index 09fcf92..a98e108 100644 --- a/channels.idx +++ b/channels.idx @@ -1,15 +1,15 @@ nimTitle channels channels.html module threading/channels 0 -nim Chan channels.html#Chan object Chan 239 -nim `=destroy` channels.html#=destroy,Chan[T] proc `=destroy`[T](c: Chan[T]) 243 -nim `=copy` channels.html#=copy,Chan[T],Chan[T] proc `=copy`[T](dest: var Chan[T]; src: Chan[T]) 259 -nim trySend channels.html#trySend,Chan[T],sinkIsolated[T] proc trySend[T](c: Chan[T]; src: sink Isolated[T]): bool 268 -nim trySend channels.html#trySend.t,Chan[T],T template trySend[T](c: Chan[T]; src: T): bool 275 -nim tryRecv channels.html#tryRecv,Chan[T],T proc tryRecv[T](c: Chan[T]; dst: var T): bool 279 -nim send channels.html#send,Chan[T],sinkIsolated[T] proc send[T](c: Chan[T]; src: sink Isolated[T]) 283 -nim send channels.html#send.t,Chan[T],T template send[T](c: Chan[T]; src: T) 291 -nim recv channels.html#recv,Chan[T],T proc recv[T](c: Chan[T]; dst: var T) 295 -nim recv channels.html#recv,Chan[T] proc recv[T](c: Chan[T]): T 299 -nim recvIso channels.html#recvIso,Chan[T] proc recvIso[T](c: Chan[T]): Isolated[T] 303 -nim peek channels.html#peek,Chan[T] proc peek[T](c: Chan[T]): int 308 -nim newChan channels.html#newChan,Positive proc newChan[T](elements: Positive = 30): Chan[T] 312 -nimgrp recv channels.html#recv-procs-all proc 295 +nim Chan channels.html#Chan object Chan 243 +nim `=destroy` channels.html#=destroy,Chan[T] proc `=destroy`[T](c: Chan[T]) 247 +nim `=copy` channels.html#=copy,Chan[T],Chan[T] proc `=copy`[T](dest: var Chan[T]; src: Chan[T]) 263 +nim trySend channels.html#trySend,Chan[T],sinkIsolated[T] proc trySend[T](c: Chan[T]; src: sink Isolated[T]): bool 272 +nim trySend channels.html#trySend.t,Chan[T],T template trySend[T](c: Chan[T]; src: T): bool 284 +nim tryRecv channels.html#tryRecv,Chan[T],T proc tryRecv[T](c: Chan[T]; dst: var T): bool 288 +nim send channels.html#send,Chan[T],sinkIsolated[T] proc send[T](c: Chan[T]; src: sink Isolated[T]) 298 +nim send channels.html#send.t,Chan[T],T template send[T](c: Chan[T]; src: T) 310 +nim recv channels.html#recv,Chan[T],T proc recv[T](c: Chan[T]; dst: var T) 314 +nim recv channels.html#recv,Chan[T] proc recv[T](c: Chan[T]): T 323 +nim recvIso channels.html#recvIso,Chan[T] proc recvIso[T](c: Chan[T]): Isolated[T] 328 +nim peek channels.html#peek,Chan[T] proc peek[T](c: Chan[T]): int 335 +nim newChan channels.html#newChan,Positive proc newChan[T](elements: Positive = 30): Chan[T] 339 +nimgrp recv channels.html#recv-procs-all proc 314 diff --git a/dochack.js b/dochack.js index 41b4ff7..078460f 100644 --- a/dochack.js +++ b/dochack.js @@ -10,44 +10,44 @@ var NTI939524179 = {size: 0, kind: 18, base: null, node: null, finalizer: null}; var NTI134217745 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; var NTI134217749 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; var NTI134217751 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; -var NTI33555169 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; -var NTI33555177 = {size: 0, kind: 22, base: null, node: null, finalizer: null}; +var NTI33555167 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; +var NTI33555175 = {size: 0, kind: 22, base: null, node: null, finalizer: null}; var NTI33554449 = {size: 0,kind: 28,base: null,node: null,finalizer: null}; var NTI33554450 = {size: 0,kind: 29,base: null,node: null,finalizer: null}; -var NTI33555176 = {size: 0, kind: 22, base: null, node: null, finalizer: null}; -var NTI33555173 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; -var NTI33555174 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; +var NTI33555174 = {size: 0, kind: 22, base: null, node: null, finalizer: null}; +var NTI33555171 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; +var NTI33555172 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; var NTI134217741 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; var NTI134217743 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; var NNI134217743 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; NTI134217743.node = NNI134217743; var NNI134217741 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; NTI134217741.node = NNI134217741; -var NNI33555174 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; -NTI33555174.node = NNI33555174; -NTI33555176.base = NTI33555173; -NTI33555177.base = NTI33555173; -var NNI33555173 = {kind: 2, len: 5, offset: 0, typ: null, name: null, sons: [{kind: 1, offset: "parent", len: 0, typ: NTI33555176, name: "parent", sons: null}, +var NNI33555172 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; +NTI33555172.node = NNI33555172; +NTI33555174.base = NTI33555171; +NTI33555175.base = NTI33555171; +var NNI33555171 = {kind: 2, len: 5, offset: 0, typ: null, name: null, sons: [{kind: 1, offset: "parent", len: 0, typ: NTI33555174, name: "parent", sons: null}, {kind: 1, offset: "name", len: 0, typ: NTI33554450, name: "name", sons: null}, {kind: 1, offset: "message", len: 0, typ: NTI33554449, name: "msg", sons: null}, {kind: 1, offset: "trace", len: 0, typ: NTI33554449, name: "trace", sons: null}, -{kind: 1, offset: "up", len: 0, typ: NTI33555177, name: "up", sons: null}]}; -NTI33555173.node = NNI33555173; -var NNI33555169 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; -NTI33555169.node = NNI33555169; -NTI33555173.base = NTI33555169; -NTI33555174.base = NTI33555173; -NTI134217741.base = NTI33555174; +{kind: 1, offset: "up", len: 0, typ: NTI33555175, name: "up", sons: null}]}; +NTI33555171.node = NNI33555171; +var NNI33555167 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; +NTI33555167.node = NNI33555167; +NTI33555171.base = NTI33555167; +NTI33555172.base = NTI33555171; +NTI134217741.base = NTI33555172; NTI134217743.base = NTI134217741; var NNI134217751 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; NTI134217751.node = NNI134217751; -NTI134217751.base = NTI33555174; +NTI134217751.base = NTI33555172; var NNI134217749 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; NTI134217749.node = NNI134217749; -NTI134217749.base = NTI33555174; +NTI134217749.base = NTI33555172; var NNI134217745 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; NTI134217745.node = NNI134217745; -NTI134217745.base = NTI33555174; +NTI134217745.base = NTI33555172; var NNI939524179 = {kind: 2, len: 2, offset: 0, typ: null, name: null, sons: [{kind: 1, offset: "a", len: 0, typ: NTI939524173, name: "a", sons: null}, {kind: 1, offset: "b", len: 0, typ: NTI33554435, name: "b", sons: null}]}; NTI939524179.node = NNI939524179; diff --git a/index.html b/index.html index 79ca224..eac65c5 100644 --- a/index.html +++ b/index.html @@ -268,7 +268,7 @@

Index

diff --git a/smartptrs.html b/smartptrs.html index 5617e35..e152c7a 100644 --- a/smartptrs.html +++ b/smartptrs.html @@ -543,7 +543,7 @@

Templates

diff --git a/theindex.html b/theindex.html index 79ca224..eac65c5 100644 --- a/theindex.html +++ b/theindex.html @@ -268,7 +268,7 @@

Index

diff --git a/waitgroups.html b/waitgroups.html index 93f3987..2cfeda2 100644 --- a/waitgroups.html +++ b/waitgroups.html @@ -194,7 +194,7 @@

Procs