Module Control.Concurrent

Support for concurrency.

Concurrency in Frege comes in 2 flavors. The first is through Threads, which are, unlike in Haskell, OS threads.

The second possibility is to use a thread pool and an executor service one can submit tasks to. But note that blocking asynchronous tasks, unlike Haskell green threads, will block an OS thread on blocking actions.

Imports

Table of Content

Definitions

data MVar a

A thread safe, shared variable, that is either full or empty.

Technically, this is just a BlockingQueue restricted to length 1.

Constructors

private MV (MutableIO (BlockingQueue a))

Member Functions

new ∷ 𝖆 → IO (MVar 𝖆)

create a MVar filled with a value

newEmptyIO (MVar 𝖆)

create an empty MVar

offerMVar 𝖆𝖆IO Bool

put a value in a MVar, returns false if already full.

pollMVar 𝖆IO (Maybe 𝖆)

get the value from a MVar, return Maybe.Nothing when empty

putMVar 𝖆𝖆IO ()

put a value in a MVar, blocks if full

takeMVar 𝖆IO 𝖆

take a value from a MVar, blocks if empty

newEmptyMVarIO (MVar 𝖆)

Alias for MVar.newEmpty

newMVar ∷ 𝖆 → IO (MVar 𝖆)

Alias for MVar.new

takeMVarMVar 𝖆IO 𝖆

Alias for MVar.take

putMVarMVar 𝖆𝖆IO ()

Alias for MVar.put

tryTakeMVarMVar 𝖆IO (Maybe 𝖆)

Alias for MVar.poll

tryPutMVarMVar 𝖆𝖆IO Bool

Alias for MVar.offer

forkOSIO ()STMutable RealWorld Thread

Create and start a new OS Thread that runs an IO action.

forkIOIO ()IO ()

Run the IO action asynchronously in an ExecutorService

This is not suitable for not-ending processes!

The executor service may manage a fixed small number of concurrent threads only.

shutdownIO ()

Shutdwon the ExecutorService

asyncIO a → IO (MVar (Exception | a))

Run a IO action asynchronously and return the result in a MVar

Functions and Values by Type

IO ()STMutable RealWorld Thread

forkOS

IO ()IO ()

forkIO

IO ()

shutdown

IO a → IO (MVar (Exception | a))

async

MutableIO (BlockingQueue a) → MVar a

MVar.MV

MVar 𝖆 → 𝖆 → IO ()

MVar.put

MVar 𝖆 → 𝖆 → IO Bool

MVar.offer

MVar 𝖆 → IO (Maybe 𝖆)

MVar.poll

MVar 𝖆 → IO 𝖆

MVar.take

𝖆 → IO (MVar 𝖆)

MVar.new

IO (MVar 𝖆)

MVar.newEmpty

Valid HTML 4.01 Strict