Skip to content

Add a way to mask thread preemption via fired timer for a computation

This follows haskell-cafe discussion http://www.haskell.org/pipermail/haskell-cafe/2014-August/115656.html. In brief: some C libraries (for example, SDL) use thread-local variables for error state of the last call. Without some way to temporarily mask timer-based lightweight thread preemption on one OS thread, there is no safe way to use such libraries and retrieve errors aside from using a global MVar (which will block all calls, not just ones on the same OS thread). For "errno" variable from C standard library, this is handled explicitly in RTS by saving its state for each lightweight thread.

So the proposal is: add new prims (something in lines of "maskPreemption#", "unmaskPreemption#" and "getPreemptionState#") which will make a computation not preemptable via fired timer and temporarily attached to one OS thread, and corresponding functions in Control.Concurrent. They should be able to be used together with "Control.Exception.mask" to also block async exceptions, if this is needed.

(I'm sorry if I've misunderstood something or did something the wrong way; I don't know the internal workings of RTS and this is my first GHC bug report).

Trac metadata
Trac field Value
Version 7.8.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System
Test case
Differential revisions
BlockedBy
Related
Blocking
CC simonmar
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information