From 520ac61dfe5a6e865cb7b10f4a822c0d72f3ded9 Mon Sep 17 00:00:00 2001 From: Lasse Blaauwbroek Date: Thu, 1 Apr 2021 09:18:00 +0200 Subject: Make critical sections safe in the presence of exceptions We introduce the `with_lock` combinator that locks a mutex in an atomic fashion. This ensures that exceptions thrown by signals will not leave the system in a deadlocked state. --- ide/coqide/idetop.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ide') diff --git a/ide/coqide/idetop.ml b/ide/coqide/idetop.ml index a6a7f7d742..2fe57ec66c 100644 --- a/ide/coqide/idetop.ml +++ b/ide/coqide/idetop.ml @@ -490,11 +490,11 @@ let eval_call c = let print_xml = let m = Mutex.create () in fun oc xml -> - Mutex.lock m; - if !Flags.xml_debug then - Printf.printf "SENT --> %s\n%!" (Xml_printer.to_string_fmt xml); - try Control.protect_sigalrm (Xml_printer.print oc) xml; Mutex.unlock m - with e -> let e = Exninfo.capture e in Mutex.unlock m; Exninfo.iraise e + CThread.with_lock m ~scope:(fun () -> + if !Flags.xml_debug then + Printf.printf "SENT --> %s\n%!" (Xml_printer.to_string_fmt xml); + try Control.protect_sigalrm (Xml_printer.print oc) xml + with e -> let e = Exninfo.capture e in Exninfo.iraise e) let slave_feeder fmt xml_oc msg = let xml = Xmlprotocol.(of_feedback fmt msg) in -- cgit v1.2.3