From 9b426d47c2964957aec58badf34f8d12e759bb7b Mon Sep 17 00:00:00 2001 From: Antonis Geralis Date: Wed, 14 Aug 2024 15:09:13 +0300 Subject: [PATCH] experiment --- threading/channels.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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: