From 816d8e6723c7272f2df0ff9e614f8a0fe19f66c9 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 21 Jan 2019 13:46:31 +0100 Subject: [thread] protect threads against sigalrm This makes the implementation of Timeout on unix more reliable since only the main thread will receive the signal for timeout. --- clib/cThread.ml | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'clib/cThread.ml') diff --git a/clib/cThread.ml b/clib/cThread.ml index 0b7955aa28..c50768b88d 100644 --- a/clib/cThread.ml +++ b/clib/cThread.ml @@ -97,3 +97,10 @@ let thread_friendly_input_value ic = end with Unix.Unix_error _ | Sys_error _ -> raise End_of_file +let protect_sigalrm f x = + begin try ignore(Thread.sigmask Unix.SIG_BLOCK [Sys.sigalrm]) + with Invalid_argument _ -> () end; + f x + +let create f x = + Thread.create (protect_sigalrm f) x -- cgit v1.2.3 From aa4f1346e7cf2f8424259143d7aca6a883d3f9d2 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 24 Jan 2019 11:09:39 +0100 Subject: add comment --- clib/cThread.ml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clib/cThread.ml') diff --git a/clib/cThread.ml b/clib/cThread.ml index c50768b88d..9e0319e8f8 100644 --- a/clib/cThread.ml +++ b/clib/cThread.ml @@ -97,6 +97,9 @@ let thread_friendly_input_value ic = end with Unix.Unix_error _ | Sys_error _ -> raise End_of_file +(* On the ocaml runtime used in some opam-for-windows version the + * [Thread.sigmask] API raises Invalid_argument "not implemented", + * hence we protect the call and turn the exception into a no-op *) let protect_sigalrm f x = begin try ignore(Thread.sigmask Unix.SIG_BLOCK [Sys.sigalrm]) with Invalid_argument _ -> () end; -- cgit v1.2.3