Skip to content

Implement combinator that forbids descheduling #180

Open
@jasagredo

Description

@jasagredo

Is your feature request related to a problem? Please describe.

Some actions are expected to be performed immediately after others, with prompt execution. I can think of two specific cases:

  • When running an async action, the TVar with the result is written, then the thread finishes. If this step is not promptly executed, the thread can remain alive leading to SloppyShutdowns.
  • When observing values from an IOSim action, it is often done via a TChan or TQueue to which we push messages when some step completed. If these are delayed, the values sent to the channel can be inconsistent with what we would like to observe from the other side of the channel.

Describe the solution you'd like

I would like to have a combinator that specifies an action cannot be descheduled, i.e. that there can't be a Yield or a Reschedule in between two actions. Something like the following:

foo :: IOSim s a
bar :: IOSim s b

promptly :: IOSim s a -> IOSim s b -> IOSim s (a, b)

baz :: IOSim s (a, b)
baz = do 
  foo `promptly` bar 

or

foo :: IOSim s a
bar :: IOSim s ()

promptly :: IOSim s a -> IOSim s () -> IOSim s a

baz :: IOSim s a
baz = do 
  foo `promptly` bar 

When evaluating foo we could look ahead and if the next action was marked promptly then forbid a reschedule.

Describe alternatives you've considered

Additional context

Could be used in the QSM PR #179. Now I am doing a hack which is checking that before sending the message to the channel that same thread id has done some action that resembles some "work" (see hasDoneWork), which was just an ad-hoc solution.

Are you willing to implement it?

  • Are you? 😃 Yes with some mentoring 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions