lifted-base-0.2.3.12: lifted IO operations from the base library

Copyright | Bas van Dijk
License | BSD-style
Maintainer | Bas van Dijk <v.dijk.bas@gmail.com>
Stability | experimental
Safe Haskell | Safe
Language | Haskell98

Control.Concurrent.Lifted

Contents

- Concurrent Haskell
- Basic concurrency operations
  - Threads with affinity
- Scheduling
  - Blocking
  - Waiting
- Communication abstractions
- Bound Threads
- Weak references to ThreadIds

Description

This is a wrapped version of Control.Concurrent with types generalized from `IO` to all monads in either `MonadBase` or `MonadBaseControl`.

Synopsis

- data ThreadId
- myThreadId :: MonadBase IO m => m ThreadId
- fork :: MonadBaseControl IO m => m () -> m ThreadId
- forkWithUnmask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
- forkFinally :: MonadBaseControl IO m => m a -> (Either SomeException a -> m ()) -> m ThreadId
- killThread :: MonadBase IO m => ThreadId -> m ()
- throwTo :: (MonadBase IO m, Exception e) => ThreadId -> e -> m ()
- forkOn :: MonadBaseControl IO m => Int -> m () -> m ThreadId
- forkOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
- getNumCapabilities :: MonadBase IO m => m Int
- setNumCapabilities :: MonadBase IO m => Int -> m ()
- threadCapability :: MonadBase IO m => ThreadId -> m (Int, Bool)
- yield :: MonadBase IO m => m ()
- threadDelay :: MonadBase IO m => Int -> m ()
- threadWaitRead :: MonadBase IO m => Fd -> m ()
- threadWaitWrite :: MonadBase IO m => Fd -> m ()
- module Control.Concurrent.MVar.Lifted
- module Control.Concurrent.Chan.Lifted
- module Control.Concurrent.QSem.Lifted
- module Control.Concurrent.QSemN.Lifted
- rtsSupportsBoundThreads :: Bool
- forkOS :: MonadBaseControl IO m => m () -> m ThreadId
- isCurrentThreadBound :: MonadBase IO m => m Bool
- runInBoundThread :: MonadBaseControl IO m => m a -> m a
- runInUnboundThread :: MonadBaseControl IO m => m a -> m a
- mkWeakThreadId :: MonadBase IO m => ThreadId -> m (Weak ThreadId)

# Concurrent Haskell

data ThreadId Source #

A `ThreadId` is an abstract type representing a handle to a thread. `ThreadId` is an instance of `Eq`, `Ord` and `Show`, where the `Ord` instance implements an arbitrary total ordering over `ThreadId`s. The `Show` instance lets you convert an arbitrary-valued `ThreadId` to string form; showing a `ThreadId` value is occasionally useful when debugging or diagnosing the behaviour of a concurrent program.

Note: in GHC, if you have a `ThreadId`, you essentially have a pointer to the thread itself. This means the thread itself can't be garbage collected until you drop the `ThreadId`. This misfeature would be difficult to correct while continuing to support `threadStatus`.

#### Instances

Instances details

Show ThreadId | Since: base-4.2.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods showsPrec :: Int -> ThreadId -> ShowS Source # show :: ThreadId -> String Source # showList :: [ThreadId] -> ShowS Source #
Eq ThreadId | Since: base-4.2.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods (==) :: ThreadId -> ThreadId -> Bool Source # (/=) :: ThreadId -> ThreadId -> Bool Source #
Ord ThreadId | Since: base-4.2.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods compare :: ThreadId -> ThreadId -> Ordering Source # (<) :: ThreadId -> ThreadId -> Bool Source # (<=) :: ThreadId -> ThreadId -> Bool Source # (>) :: ThreadId -> ThreadId -> Bool Source # (>=) :: ThreadId -> ThreadId -> Bool Source # max :: ThreadId -> ThreadId -> ThreadId Source # min :: ThreadId -> ThreadId -> ThreadId Source #

# Basic concurrency operations

myThreadId :: MonadBase IO m => m ThreadId Source #

Generalized version of `myThreadId`.

fork :: MonadBaseControl IO m => m () -> m ThreadId Source #

Generalized version of `forkIO`.

Note that, while the forked computation `m ()` has access to the captured state, all its side-effects in `m` are discarded. It is run only for its side-effects in `IO`.

forkWithUnmask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId Source #

Generalized version of `forkIOWithUnmask`.

Note that, while the forked computation `m ()` has access to the captured state, all its side-effects in `m` are discarded. It is run only for its side-effects in `IO`.

forkFinally :: MonadBaseControl IO m => m a -> (Either SomeException a -> m ()) -> m ThreadId Source #

Generalized version of `forkFinally`.

Note that in `forkFinally action and_then`, while the forked `action` and the `and_then` function have access to the captured state, all their side-effects in `m` are discarded. They're run only for their side-effects in `IO`.

killThread :: MonadBase IO m => ThreadId -> m () Source #

Generalized version of `killThread`.

throwTo :: (MonadBase IO m, Exception e) => ThreadId -> e -> m () Source #

Generalized version of `throwTo`.

## Threads with affinity

forkOn :: MonadBaseControl IO m => Int -> m () -> m ThreadId Source #

Generalized version of `forkOn`.

Note that, while the forked computation `m ()` has access to the captured state, all its side-effects in `m` are discarded. It is run only for its side-effects in `IO`.

forkOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId Source #

Generalized version of `forkOnWithUnmask`.

Note that, while the forked computation `m ()` has access to the captured state, all its side-effects in `m` are discarded. It is run only for its side-effects in `IO`.

getNumCapabilities :: MonadBase IO m => m Int Source #

Generalized version of `getNumCapabilities`.

setNumCapabilities :: MonadBase IO m => Int -> m () Source #

Generalized version of `setNumCapabilities`.

threadCapability :: MonadBase IO m => ThreadId -> m (Int, Bool) Source #

Generalized version of `threadCapability`.

# Scheduling

yield :: MonadBase IO m => m () Source #

Generalized version of `yield`.

## Blocking

## Waiting

threadDelay :: MonadBase IO m => Int -> m () Source #

Generalized version of `threadDelay`.

threadWaitRead :: MonadBase IO m => Fd -> m () Source #

Generalized version of `threadWaitRead`.

threadWaitWrite :: MonadBase IO m => Fd -> m () Source #

Generalized version of `threadWaitWrite`.

# Communication abstractions

module Control.Concurrent.MVar.Lifted

module Control.Concurrent.Chan.Lifted

module Control.Concurrent.QSem.Lifted

module Control.Concurrent.QSemN.Lifted

# Bound Threads

rtsSupportsBoundThreads :: Bool Source #

`True` if bound threads are supported. If `rtsSupportsBoundThreads` is `False`, `isCurrentThreadBound` will always return `False` and both `forkOS` and `runInBoundThread` will fail.

forkOS :: MonadBaseControl IO m => m () -> m ThreadId Source #

Generalized version of `forkOS`.

Note that, while the forked computation `m ()` has access to the captured state, all its side-effects in `m` are discarded. It is run only for its side-effects in `IO`.

isCurrentThreadBound :: MonadBase IO m => m Bool Source #

Generalized version of `isCurrentThreadBound`.

runInBoundThread :: MonadBaseControl IO m => m a -> m a Source #

Generalized version of `runInBoundThread`.

runInUnboundThread :: MonadBaseControl IO m => m a -> m a Source #

Generalized version of `runInUnboundThread`.

# Weak references to ThreadIds

mkWeakThreadId :: MonadBase IO m => ThreadId -> m (Weak ThreadId) Source #

Generalized versio of `mkWeakThreadId`.