diff --git a/threading/channels.nim b/threading/channels.nim index 10f3371..f55cce4 100644 --- a/threading/channels.nim +++ b/threading/channels.nim @@ -187,8 +187,9 @@ proc channelSend(chan: ChannelRaw, data: pointer, size: int, blocking: static bo when not blocking: if chan.isFull(): return false - - acquire(chan.lock) + if not tryAcquire(chan.lock): return false + else: + acquire(chan.lock) # check for when another thread was faster to fill when blocking: @@ -221,8 +222,9 @@ proc channelReceive(chan: ChannelRaw, data: pointer, size: int, blocking: static when not blocking: if chan.isEmpty(): return false - - acquire(chan.lock) + if not tryAcquire(chan.lock): return false + else: + acquire(chan.lock) # check for when another thread was faster to empty when blocking: