Race condition when multiple threads wait for a process
Consider the following code:
import System.Process import Control.Concurrent.Async main :: IO () main = do (_, _, _, ph) <- createProcess $ shell "sleep 1" let helper i = do ec <- waitForProcess ph print (i :: Int, ec) ((), ()) <- concurrently (helper 1) (helper 2) return ()
If I compile with the single threaded runtime, I get the output
But when compiling with the multithreaded runtime, I get:
bin: waitForProcess: does not exist (No child processes)
If you need to wait for a process from multiple threads, you can do so now by having a dedicated wait thread which writes to an MVar or TMVar, but the current default behavior can be surprising.
At the least, I think we need better documentation, but if there's a better solution, that would be best.