From 2c722f55894a716d48e75153bc376f82c80f94a6 Mon Sep 17 00:00:00 2001 From: Fay Carsons Date: Sat, 20 Apr 2024 14:40:00 -0400 Subject: [PATCH] lock owner demonitor on unlock --- riot/lib/mutex.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/riot/lib/mutex.ml b/riot/lib/mutex.ml index 374c9b47..c8a15ae7 100644 --- a/riot/lib/mutex.ml +++ b/riot/lib/mutex.ml @@ -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 ()); @@ -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