Way to determine if code is running in thread fixed on capability
|Reported by:||mitar||Owned by:||simonmar|
|Type of failure:||None/Unknown||Test Case:|
|Related Tickets:||Differential Revisions:|
I would request a way to determine if code is running in thread fixed on capability, that is in thread created by forkOnIO. Furthermore I would like to request a way to get number of this capability. Something like:
wasForkedOnIO :: IO (Maybe Int)
The reason for this is that I would like to know in my code if it is running on fixed capability so that I would also further threads spawn on this same capability.
This is useful for FFI libraries which require that all code runs in the same (OS) thread, while still allowing Haskell threads to work with that library. There will be not much of parallelism boost because of that but code can be much nicer: you can spawn few Haskell threads each doing its own thing while RTS interweave all this together. So code can be more modular while still running on one OS thread. Something like easy coroutines.
An example of this is X11 library. It supports threading but by enabling it performance of whole Haskell program really drops a lot (probably locking it does is not really nice for Haskell itself). By fixing all Haskell threads which work with X11 library to one OS thread you do not need to enable threading in X11 library and performance and responsiveness is great. And an example of when code is nicer for X11 if using threads is when you want to process key events independently from drawing process. So one threads needs fast response to key events, and another threads draws things to the screen. Trying to write this together means coupling key events with drawing code.
So, to be able to write code in modular fashion and without hard-coded capability numbers such primitive mentioned above would be really useful.
Change History (3)
comment:1 Changed 4 years ago by simonmar
- Architecture changed from x86_64 (amd64) to Unknown/Multiple
- Milestone set to 7.2.1
- Operating System changed from Linux to Unknown/Multiple
- Owner set to simonmar
- Priority changed from normal to high