Restore the correct sigmask in systhreads#11880
Merged
shindere merged 1 commit intoocaml:trunkfrom Jan 11, 2023
Merged
Conversation
Contributor
|
Many thanks for a nice little fix!
Given that you have taken the time to write a program to illustrate the
problem, how about adding it to the testsuite? Would it seem relevant?
I can help with converting it into a test, if needed and it's
appropriate to add this as a test.
|
Contributor
Author
Sure thing ! I can add it, but first I have to go buy some chocolate, I'll do it later tonight 👍 |
Contributor
|
Okay nice! Have a nice chocolate!
|
Contributor
Author
|
I've just piggybacked the test on |
haesbaert
added a commit
to haesbaert/ocaml
that referenced
this pull request
Jan 10, 2023
haesbaert
added a commit
to haesbaert/ocaml
that referenced
this pull request
Jan 10, 2023
The code correctly blocks and restores the signal mask on the parent while creating a systhread, but the new mask, not the old mask was being passed down the child to be restored.
The code correctly blocks and restores the signal mask on the parent while creating a systhread, but the new mask, not the old mask was being passed down the child to be restored.
Contributor
|
Christiano Haesbaert (2023/01/10 11:44 -0800):
I've just piggybacked the test on
`testsuite/tests/lib-systhreads/threadsigmask.ml`, I see no sense in
putting it in a separate file.
Given the diff your choice looks very sensible to me, many thanks!
|
Contributor
Author
|
squashed as requested |
shindere
approved these changes
Jan 11, 2023
haesbaert
added a commit
to haesbaert/eio
that referenced
this pull request
Jan 23, 2023
This makes sure we can process signals in luv the same way we do in uring. As stated in ocaml-multicore#400 the main issue is that luv's mainloop will restart on EINTR and we will never unwind back to ocaml land, so even though the process got the signal, the runtime will not see it until something else goes on. The trick here is to abuse POSIX thread semantics and shove all signals into one specific systhread by blocking them in the other threads. Additionally, I've fixed a bug in Ocaml 5.0 where the systhreads end up starting with all signals blocked: ocaml/ocaml#11880. This PR works even with/without the bug. Danger Zone ~~~~~~~~~~~ This is tricky ! If you're thinking we can do better than pipes, think again ! Unix.sigsuspend doesn't work on multithreaded, we don't have a real Unix.pause (it's implemented on top of sigsuspend !). The semantics for kill(2) to "self" are different than "from outside" when multithreaded, and the runtime doesn't expose pthread_kill(2). That's why on the test we have to fork and signal back to the parent. I know, it's horrible.
talex5
added a commit
to haesbaert/eio
that referenced
this pull request
Jan 24, 2023
This makes sure we can process signals in luv the same way we do in uring. As stated in ocaml-multicore#400 the main issue is that luv's mainloop will restart on EINTR and we will never unwind back to ocaml land, so even though the process got the signal, the runtime will not see it until something else goes on. The trick here is to abuse POSIX thread semantics and shove all signals into one specific systhread by blocking them in the other threads. Additionally, I've fixed a bug in OCaml 5.0 where the systhreads end up starting with all signals blocked: ocaml/ocaml#11880. This PR works even with/without the bug. Danger Zone ~~~~~~~~~~~ This is tricky ! If you're thinking we can do better than pipes, think again ! Unix.sigsuspend doesn't work on multithreaded, we don't have a real Unix.pause (it's implemented on top of sigsuspend !). The semantics for kill(2) to "self" are different than "from outside" when multithreaded, and the runtime doesn't expose pthread_kill(2). That's why on the test we have to fork and signal back to the parent. I know, it's horrible. Co-authored-by: Thomas Leonard <talex5@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The code correctly blocks and restores the signal mask on the parent while creating a systhread, but the new mask, not the old mask was being passed down the child to be restored.
The bug results on every systhread being run with all signals masked, which does not seem to be the intent, otherwise the
init_maskhas no function.The following program shows the bug with before and after outputs:
Before:
After: