#4457: Way to determine if code is running in thread fixed on capability
--------------------------------+-------------------------------------------
Reporter: mitar | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler
Version: 6.12.3 | Keywords:
Testcase: | Blockedby:
Os: Linux | Blocking:
Architecture: x86_64 (amd64) | Failure: None/Unknown
--------------------------------+-------------------------------------------
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.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4457>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs