Skip to content

scheduler: use semaphore for event wakeups#14550

Open
rgrinberg wants to merge 1 commit into
ocaml:mainfrom
rgrinberg:push-ryovxzwtnozt
Open

scheduler: use semaphore for event wakeups#14550
rgrinberg wants to merge 1 commit into
ocaml:mainfrom
rgrinberg:push-ryovxzwtnozt

Conversation

@rgrinberg
Copy link
Copy Markdown
Member

scheduler: handle signals on the main thread

Replace the dedicated signal watcher thread with C signal handlers that record pending signals in a static table and wake the scheduler event queue. The OCaml scheduler drains that table into signal events on the main thread, so SIGINT/SIGQUIT/SIGTERM, SIGCHLD, and SIGUSR2 stay integrated with the normal event loop.

Block scheduler signals while spawning worker threads so those threads inherit a blocked signal mask, then leave the main thread unblocked after installing the C handlers.

Use a C wakeup primitive for the event queue so signal handlers can wake an idle scheduler without calling into OCaml runtime synchronization. Preserve the quick repeated Ctrl-C emergency exit behavior and keep SIGUSR2 debug dumps working.

Also set local XDG_RUNTIME_DIR values in affected cram tests so RPC registry files stay inside the writable test sandbox.

@rgrinberg
Copy link
Copy Markdown
Member Author

@anmonteiro this is quite similar to your original PR except without the signal watching thread + pipe completely removed. If you could test this on macos, it would be appreciated.

@rgrinberg rgrinberg force-pushed the push-ryovxzwtnozt branch 3 times, most recently from de9ef5e to f58c3a6 Compare May 16, 2026 20:45
Replace the dedicated signal watcher thread with C signal handlers that
record pending signals in a static table and wake the scheduler event
queue. The OCaml scheduler drains that table into signal events on the
main thread, so SIGINT/SIGQUIT/SIGTERM, SIGCHLD, and SIGUSR2 stay
integrated with the normal event loop.

Block scheduler signals while spawning worker threads so those threads
inherit a blocked signal mask, then leave the main thread unblocked
after installing the C handlers.

Use a C wakeup primitive for the event queue so signal handlers can wake
an idle scheduler without calling into OCaml runtime synchronization.
Preserve the quick repeated Ctrl-C emergency exit behavior and keep
SIGUSR2 debug dumps working.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
@rgrinberg rgrinberg force-pushed the push-ryovxzwtnozt branch from f58c3a6 to 2acad14 Compare May 18, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant