Skip to content

Commit

Permalink
Merge pull request #5359 from edwintorok/private/edvint/pasyncbug2
Browse files Browse the repository at this point in the history
CA-387699: Fix Protocol_async.with_lock bug spotted by Vincent
  • Loading branch information
edwintorok authored Jan 16, 2024
2 parents fed3403 + 362fc3d commit b55c748
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ocaml/message-switch/async/protocol_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ module M = struct
{m; c}

let with_lock t f =
let rec wait state =
if Bool.(t.m = state) then
let rec wait () =
if Bool.(t.m = false) then (
t.m <- true ;
return ()
else
Condition.wait t.c >>= fun () -> wait state
) else
Condition.wait t.c >>= wait
in
wait false >>= fun () ->
t.m <- true ;
wait () >>= fun () ->
Monitor.protect f ~finally:(fun () ->
t.m <- false ;
Condition.broadcast t.c () ;
Expand Down

0 comments on commit b55c748

Please sign in to comment.