[Haskell-cafe] How to ensure code executes in the context of a specific OS thread?
dagitj at gmail.com
Mon Jul 4 07:02:33 CEST 2011
I'm trying to get some GUI code working on OSX and numerous forums
around the internet keep reiterating that on OSX to correctly handle
GUI events you need to use the original thread allocated to your
process to check for events and to call the Cocoa framework
functionality. Specifically, using a secondary thread (even a bound
thread) is not sufficient with the Cocoa framework.
I looked at the threading documentation in Control.Concurrent for GHC
and it's not clear to me if this is even possible with GHC without
restricting to the non-threaded RTS. This means that using the GUI
library from GHCI is not an option and using multiple OS threads in
the final application is also not possible. This means that some FFI
libraries will be unusable.
My main question is, is there a way around this so that I could, for
example, use the library from GHCI?
My second question is, if there is no current workaround then how can
we remedy this situation? It seems like there could be an api
runOnOriginalThread :: IO a -> IO a
This function would be similar to runInBoundThread except it would be
guaranteed to run on the original thread allocated to the ghc/ghci
process. I believe the above primitive would be sufficient.
I'll worry about filing a bug or making a libraries proposal after I
have a better understanding of what must be done.
More information about the Haskell-Cafe