New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread.delay blocks signal delivery in OCaml 4.07 #7903
Comments
Comment author: lindig
|
Comment author: @edwintorok It might be useful for the stdlib implementation to reacquire the ocaml runtime lock, run the equivalent of caml_process_signals, and release the runtime lock again (perhaps by tracking how long that took via gettimeofday). |
Comment author: lindig diff --git a/otherlibs/systhreads/thread.ml b/otherlibs/systhreads/thread.ml (* Wait functions *) -let delay time = ignore(Unix.select [] [] [] time) let wait_read fd = () |
Comment author: lindig In the case of EINTR the runtime system could check for signals and deliver them. CAMLprim value unix_sleep(value duration) |
Comment author: lindig Can we get an opinion on this? If the changed in behaviour in OCaml 4.07 is as intended, how should one terminate sleeping threads? it could mean that threads never should sleep long to guarantee that signals can be delivered. |
Comment author: @jhjourdan
Sorry for the delay. I will have a look at some point during the week.
Indeed, this seems possible. However, the signal handling system in the OCaml runtime is subtle, and we have to make sure this does not have unexpected implications. |
Comment author: @xavierleroy Sorry I didn't see this report earlier. Yes, the 4.07 behavior is not quite right and an unintended consequence. We could enter/leave around each call to nanosleep: do { I think this would call signal handlers in a timely manner. However, the extra leave / enter calls can take arbitrarily long time, so we can end up sleeping too long. |
Comment author: @jhjourdan
Isn't that already the behavior the the libC? I mean, if you write a pure C program which contains time-consuming signal handlers, then the sleep-like functions are not a suitable way of pausing an accurate amount of time. |
Comment author: @xavierleroy Proposed fix at #2306 |
Comment author: @xavierleroy Fixed in commit 187ceb6. |
Original bug ID: 7903
Reporter: lindig
Assigned to: @xavierleroy
Status: resolved (set by @xavierleroy on 2019-03-11T09:40:14Z)
Resolution: fixed
Priority: normal
Severity: minor
Platform: Unix
OS: Linux
Version: 4.07.1
Target version: 4.09.0+dev
Fixed in version: 4.09.0+dev
Category: runtime system and C interface
Monitored by: robhoes @ygrek
Bug description
A thread in Thread.delay won't receive a signal like SIGTERM in OCaml 4.07 but it did in OCaml 4.06. This makes it difficult to end a process that is delayed in a thread. This might be a deliberate change but I would like to see it discussed.
Steps to reproduce
(* ocamlc -thread -o foo unix.cma threads.cma foo.ml
*)
let on_sigterm _ =
prerr_endline "Received signal";
flush stderr;
exit 0
let () =
Sys.set_signal Sys.sigterm Sys.(Signal_handle on_sigterm);
Sys.catch_break true;
while true; do
Thread.delay 300.
done
Control C does not end the thread while it is in Thread.delay.
The text was updated successfully, but these errors were encountered: