[GHC] #9519: Add a way to mask thread preemption via fired timer for a computation

#9519: Add a way to mask thread preemption via fired timer for a computation -------------------------------------+------------------------------------- Reporter: abbradar | Owner: simonmar Type: feature request | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.8.2 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- 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). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9519 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9519: Add a way to mask thread preemption via fired timer for a computation -------------------------------------+------------------------------------- Reporter: abbradar | Owner: simonmar Type: feature | Status: infoneeded request | Milestone: Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by simonmar): * status: new => infoneeded Comment: I doubt that this would be easily implementable, the RTS assumes that worker threads are interchangeable and I think it would be difficult (and error-prone) to change that assumption. The right way to deal with thread-local state is to use a bound thread (`forkOS`). Is that a problem? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9519#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9519: Add a way to mask thread preemption via fired timer for a computation -------------------------------------+------------------------------------- Reporter: abbradar | Owner: simonmar Type: feature | Status: infoneeded request | Milestone: Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by abbradar): Well, not really -- it was just an idea that, if could be implemented more or less easily, could allow using lightweight threads instead. Thanks for the clarification! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9519#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9519: Add a way to mask thread preemption via fired timer for a computation -------------------------------------+------------------------------------- Reporter: abbradar | Owner: simonmar Type: feature | Status: closed request | Milestone: Priority: normal | Version: 7.8.2 Component: Runtime | Keywords: System | Architecture: Unknown/Multiple Resolution: wontfix | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by simonmar): * status: infoneeded => closed * resolution: => wontfix -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9519#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC