-
Notifications
You must be signed in to change notification settings - Fork 82
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
Export runInteractiveProcess_lock on Posix systems #154
Conversation
I don't feel strongly either way, but overall I'm concerned that there may be undocumented invariants, and exposing this locking primitive will end up encouraging misuse. |
Yes, agreed this is not pretty but it seems to be forced by the design of the RTS. If there were some facility provided by the language itself to ensure that an FFI fork call is safe, then libraries wouldn't have to come up with their own locking schemes. As it stands, other libraries can't safely fork if that operation might get interleaved with a It seems like a reasonable compromise to put it in |
Fair enough. In that case, can you add a changelog entry, and some Haddocks on the |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Np! Any chance I could get you to cut a Hackage release @snoyberg ? |
Done! |
This PR is to help fix merijn/posix-pty#15.
Summary: on Posix systems,
System.Process
must take certain precautions before using thefork
system call. These include altering global state by callingblockUserSignals
andstopTimer()
before forking; see https://github.com/haskell/process/blob/master/cbits/runProcess.c#L137.However,
System.Process
is not the only library that might need to use fork.System.Posix.Pty
is another such library -- it uses theforkpty
call (which internally doesfork
) to create a process attached to a pseudo-terminal. Thus System.Posix.Pty also needs to take these precautions.As a result, we need to ensure mutual exclusion between
System.Posix.Pty
fork calls andSystem.Process
fork calls, or else they stomp on each other's changes to global state. The only way I can see to do this is to use the same lock, so this PR exports it. I made a PR onposix-pty
to leverage it here: merijn/posix-pty#16.Of course, this feels like a bit of a band-aid since it only ensures that interleaving these two libraries is safe. Other libraries that might want to
fork
will still run into problems interleaving with these libraries. It would be nice to get some GHC expert attention on this but maybe that's an issue for another tracker.