From 67bc47181c82d3cc5b3ad3ceb77acc6451b29bca Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 15 Jun 2023 22:24:58 -0400 Subject: [PATCH] fix: in blocking queue, `pop` works on a non empty closed queue --- src/bb_queue.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bb_queue.ml b/src/bb_queue.ml index 1cec05db..df23d980 100644 --- a/src/bb_queue.ml +++ b/src/bb_queue.ml @@ -37,10 +37,12 @@ let push (self : _ t) x : unit = let pop (self : 'a t) : 'a = Mutex.lock self.mutex; let rec loop () = - if self.closed then ( - Mutex.unlock self.mutex; - raise Closed - ) else if Queue.is_empty self.q then ( + if Queue.is_empty self.q then ( + if self.closed then ( + Mutex.unlock self.mutex; + raise Closed + ); + Condition.wait self.cond self.mutex; (loop [@tailcall]) () ) else (