Bugs (with fixes) in withThread and runInUnboundThread
To quote my mail to the libraries list:
I discovered two similar bugs in Control.Concurrent:
- In the function: 'runInUnboundThread' a thread is forked which first installs an exception handler before performing the given IO
computation. However it should first block asynchronous exceptions before forking the thread to ensure that the exception handler is always installed. In the attached patch I use the 'blockedApply' function which also ensures that the forked IO computation has the same blocked state as its parent thread.
- There's a similar problem in the internal withThread function (which AFAICS is only called in threadWaitRead). withThead also forgets to properly block asynchronous exceptions before forking a thread which needs to install an exception handler. In this case I didn't use blockedApply but only used block because withThread is only called with 'waitFd' which only performs an FFI call which can't receive asynchronous exceptions anyway.