diff --git a/threading/channels.nim b/threading/channels.nim index e426508..fe616a4 100644 --- a/threading/channels.nim +++ b/threading/channels.nim @@ -187,9 +187,8 @@ proc channelSend(chan: ChannelRaw, data: pointer, size: int, blocking: static bo when not blocking: if chan.isFull(): return false - if not tryAcquire(chan.lock): return false - else: - acquire(chan.lock) + + acquire(chan.lock) # check for when another thread was faster to fill when blocking: @@ -222,9 +221,8 @@ proc channelReceive(chan: ChannelRaw, data: pointer, size: int, blocking: static when not blocking: if chan.isEmpty(): return false - if not tryAcquire(chan.lock): return false - else: - acquire(chan.lock) + + acquire(chan.lock) # check for when another thread was faster to empty when blocking: @@ -295,6 +293,9 @@ proc trySend*[T](c: Chan[T], src: sink Isolated[T]): bool {.inline.} = ## Doesn't block waiting for space in the channel to become available. ## Instead returns after an attempt to send a message was made. ## + ## .. warning:: Blocking may occur if another thread holds the internal lock on + ## the channel's buffer, causing the thread to wait until the lock is released. + ## ## .. warning:: In high-concurrency situations, consider using an exponential ## backoff strategy to reduce contention and improve the success rate of ## operations. @@ -320,6 +321,9 @@ proc tryTake*[T](c: Chan[T], src: var Isolated[T]): bool {.inline.} = ## Doesn't block waiting for space in the channel to become available. ## Instead returns after an attempt to send a message was made. ## + ## .. warning:: Blocking may occur if another thread holds the internal lock on + ## the channel's buffer, causing the thread to wait until the lock is released. + ## ## .. warning:: In high-concurrency situations, consider using an exponential ## backoff strategy to reduce contention and improve the success rate of ## operations. @@ -335,6 +339,9 @@ proc tryRecv*[T](c: Chan[T], dst: var T): bool {.inline.} = ## ## Doesn't block waiting for messages in the channel to become available. ## Instead returns after an attempt to receive a message was made. + ## + ## .. warning:: Blocking may occur if another thread holds the internal lock on + ## the channel's buffer, causing the thread to wait until the lock is released. ## ## .. warning:: In high-concurrency situations, consider using an exponential ## backoff strategy to reduce contention and improve the success rate of