From c4e92faaf7bbad53abd6e3ed01f7ecc67549e165 Mon Sep 17 00:00:00 2001 From: Sam Fredrickson Date: Wed, 1 Mar 2023 01:03:31 -0800 Subject: [PATCH] Fix wait condition and ordering in send(). --- precise/lib.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/precise/lib.go b/precise/lib.go index 171f1fb..82fa01d 100644 --- a/precise/lib.go +++ b/precise/lib.go @@ -138,12 +138,12 @@ func (s *state[T]) send(value T, buf *circ.B[T], cond *sync.Cond) { s.mu.Lock() defer s.mu.Unlock() for { + for !s.closed && !buf.CanPush() { + cond.Wait() + } if s.closed { panic("send on closed queue") } - for !buf.CanPush() { - cond.Wait() - } if buf.CanPush() { buf.PushBack(value) s.canRecv.Broadcast()