diff options
| author | Enrico Tassi | 2019-01-21 13:46:31 +0100 |
|---|---|---|
| committer | Enrico Tassi | 2019-01-22 18:03:18 +0100 |
| commit | 816d8e6723c7272f2df0ff9e614f8a0fe19f66c9 (patch) | |
| tree | 08547fb1a9ef780d2e7b56e99de17db3866f7b89 /clib | |
| parent | 05e2222e04323d11429d659b415750cf40e2babd (diff) | |
[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.
Diffstat (limited to 'clib')
| -rw-r--r-- | clib/cThread.ml | 7 | ||||
| -rw-r--r-- | clib/cThread.mli | 3 |
2 files changed, 10 insertions, 0 deletions
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 diff --git a/clib/cThread.mli b/clib/cThread.mli index acc5a60c09..b090479c4c 100644 --- a/clib/cThread.mli +++ b/clib/cThread.mli @@ -26,3 +26,6 @@ val thread_friendly_really_read : thread_ic -> Bytes.t -> off:int -> len:int -> unit val thread_friendly_really_read_line : thread_ic -> string +(* Wrapper around Thread.create that blocks signals such as Sys.sigalrm (used + * for Timeout *) +val create : ('a -> 'b) -> 'a -> Thread.t |
