Skip to content

Commit

Permalink
lock owner demonitor on unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
FayCarsons committed Apr 20, 2024
1 parent bfcf4ea commit 2c722f5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions riot/lib/mutex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ let selector = function
`select m
| _ -> `skip

(* NOTE: (@faycarsons) Monitoring should(?) prevent deadlocks caused by mutex
process dying *)
(* Monitor mutex process to catch crashes *)
let wait_lock mutex : (unit, [> error ]) result =
monitor mutex.process;
send mutex.process @@ Lock (self ());
Expand All @@ -99,7 +98,9 @@ let try_wait_lock mutex =
let wait_unlock mutex =
send mutex.process @@ Unlock (self ());
match[@warning "-8"] receive ~selector () with
| Unlock_accepted -> Ok ()
| Unlock_accepted ->
demonitor mutex.process;
Ok ()
| Failed reason -> Error reason
| Monitor (Process_down _) -> Error `process_died

Expand Down

0 comments on commit 2c722f5

Please sign in to comment.