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 = let pop (self : 'a t) : 'a =
Mutex.lock self.mutex; Mutex.lock self.mutex;
let rec loop () = let rec loop () =
if self.closed then ( if Queue.is_empty self.q then (
Mutex.unlock self.mutex; if self.closed then (
raise Closed Mutex.unlock self.mutex;
) else if Queue.is_empty self.q then ( raise Closed
);
Condition.wait self.cond self.mutex; Condition.wait self.cond self.mutex;
(loop [@tailcall]) () (loop [@tailcall]) ()
) else ( ) else (