fix: in blocking queue, pop works on a non empty closed queue

This commit is contained in:
Simon Cruanes 2023-06-15 22:24:58 -04:00
parent 4e112e1591
commit 67bc47181c
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -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 (