concurrency
Typeclasses, functions, and data types for concurrency and STM.
https://github.com/barrucadu/dejafu
| Version on this page: | 1.4.0.0 |
| LTS Haskell 24.18: | 1.11.0.3 |
| Stackage Nightly 2025-11-01: | 1.11.0.3 |
| Latest on Hackage: | 1.11.0.3 |
concurrency-1.4.0.0@sha256:e197ddd4678c9bba99eca747fc6a9377382f699adf88944aba82de10632e635d,2795Module documentation for 1.4.0.0
- Control
- Control.Concurrent
- Control.Monad
- Control.Monad.Conc
- Control.Monad.STM
concurrency
A typeclass abstraction over much of Control.Concurrent (and some extras!). If you’re looking for a general introduction to Haskell concurrency, you should check out the excellent Parallel and Concurrent Programming in Haskell, by Simon Marlow. If you are already familiar with concurrent Haskell, just change all the imports from Control.Concurrent.* to Control.Concurrent.Classy.* and fix the type errors.
A brief list of supported functionality:
- Threads: both unbound and bound.
- Getting and setting capablities.
- Yielding and delaying.
- Mutable state: STM,
MVar, andIORef. - Atomic compare-and-swap for
IORef. - Exceptions.
- All of the data structures in Control.Concurrent.* and Control.Concurrent.STM.* have typeclass-abstracted equivalents.
- A reimplementation of the async package, providing a
higher-level interface over threads, allowing users to conveniently
run
MonadConcoperations asynchronously and wait for their results.
This is quite a rich set of functionality, although it is not complete. If there is something else you need, file an issue!
This used to be part of dejafu, but with the dejafu-0.4.0.0 release, it was split out into its own package.
The documentation of the latest developmental version is available online.
Why this and not something else?
-
Why not base: like lifted-base, concurrency uses typeclasses to make function types more generic. This automatically eliminates calls to
liftin many cases, resulting in clearer and simpler code. -
Why not lifted-base: fundamentally, lifted-base is still using actual threads and actual mutable variables. When using a concurrency-specific typeclass, this isn’t necessarily the case. The dejafu library provides non-IO-based implementations to allow testing concurrent programs.
-
Why not IOSpec: IOSpec provides many of the operations this library does, however it uses a free monad to do so, which has extra allocation overhead. Furthermore, it does not expose enough of the internals in order to accurately test real-execution semantics, such as relaxed memory.
Contributing
Bug reports, pull requests, and comments are very welcome!
Feel free to contact me on GitHub, through IRC (#haskell on freenode), or email ([email protected]).
Changes
Release Notes
All notable changes to this project will be documented in this file.
This project is versioned according to the Package Versioning Policy, the de facto standard Haskell versioning scheme.
1.4.0.0
- Date 2017-01-19
- Git tag concurrency-1.4.0.0
- Hackage https://hackage.haskell.org/package/concurrency-1.4.0.0
Control.Monad.Conc.Class
-
The
peekTicket'now has a more concrete type, to make deriving newtype instances ofMonadConcpossible.- Old:
MonadConc m => proxy m -> Ticket m a -> a - New:
MonadConc m => Proxy m -> Ticket m a -> a
- Old:
1.3.0.0
- Date 2017-12-23
- Git tag concurrency-1.3.0.0
- Hackage https://hackage.haskell.org/package/concurrency-1.3.0.0
Control.Concurrent.Classy.Async
- New
asyncBound,asyncBoundN,withAsyncBound, andwithAsyncBoundNfunctions for doing asynchronous actions on bound threads. (#126)
Control.Monad.Conc.Class
-
MonadConcnow supports bound threads with newforkOS,forkOSN, andisCurrentThreadBoundfunctions. (#126) -
New
runInBoundThreadandrunInUnboundThreadfunctions. (#126) -
The
rtsSupportsBoundThreadsdefinition is now the definition from Control.Concurrent re-exported, not justFalse. (#126)
Note that bound threads are only supported if you compile with GHC and link with -threaded.
1.2.3.0
- Date 2017-11-30
- Git tag concurrency-1.2.3.0
- Hackage https://hackage.haskell.org/package/concurrency-1.2.3.0
Control.Concurrent.Classy.Async
- New named-thread variants of the
withAsync*functions:withAsyncN,withAsyncOnN,withAsyncWithUnmaskN, andwithAsyncOnWithUnmaskN(#148).
1.2.2.0
- Date 2017-11-05
- Git tag concurrency-1.2.2.0
- Hackage https://hackage.haskell.org/package/concurrency-1.2.2.0
Control.Monad.Conc.Class
-
A new
IsConctype (andtoIsConc,fromIsConcfunctions), where a value of typeIsConc m acan only be constructed ifmhas aMonadConcinstance. ItsSTMtype isIsSTM (STM m). (#144) -
The provided transformer instances now use the
modifyCRefCAS_of the underlying monad, rather than the default definition in terms ofmodifyCRefCAS.
Control.Monad.STM.Class
- A new
IsSTMtype (andtoIsSTM,fromIsSTMfunctions), where a value of typeIsSTM m acan only be constructed ifmhas aMonadSTMinstance. (#144)
1.2.1.2
- Date 2017-10-14
- Git tag concurrency-1.2.1.2
- Hackage https://hackage.haskell.org/package/concurrency-1.2.1.2
Control.Monad.Conc.Class
- Fixes an infinite loop introduced for the
IOinstance ofMonadConcinforkWithUnmaskandforkOnWithUnmaskin 1.2.1.1 (#134).
1.2.1.1
- Date 2017-10-11
- Git tag concurrency-1.2.1.1
- Hackage https://hackage.haskell.org/package/concurrency-1.2.1.1
Control.Monad.Conc.Class
- The
IOinstance ofMonadConcnow names threads withGHC.Conc.labelThread, so thread names now appear in debugging traces of normal execution.
1.2.1.0
- Date 2017-10-02
- Git tag concurrency-1.2.1.0
- Hackage https://hackage.haskell.org/package/concurrency-1.2.1.0
Control.Concurrent.Classy.Async
- New named-thread variants of the
async*functions:asyncN,asyncOnN,asyncWithUnmaskN, andasyncOnWithUnmaskN(#125).
1.2.0.0
- Date 2017-09-16
- Git tag concurrency-1.2.0.0
- Hackage https://hackage.haskell.org/package/concurrency-1.2.0.0
Control.Monad.STM.Class
MonadSTMnow has aMonadPlusconstraint.- The
orElseandretryfunctions have been promoted to top-level definitions, and are aliases formplusandmzero.
1.1.2.1
- Date 2017-06-07
- Git tag concurrency-1.1.2.1
- Hackage https://hackage.haskell.org/package/concurrency-1.1.2.1
Changed
- The
isEmptyMVarfunction is now implemented usingtryReadMVarinstead of a combination oftryTakeMVarandputMVar. It no longer modifies the contents of theMVarand can no longer block.
Miscellaneous
- There is now a changelog.
1.1.2.0
- Date 2017-04-05
- Git tag concurrency-1.1.2.0
- Hackage https://hackage.haskell.org/package/concurrency-1.1.2.0
Control.Concurrent.Classy.Async
- New functions:
uninterruptibleCancelfunction, which iscancelinside an uninterruptible mask.replicateConcurrentlyfunction, which performs an action many times in separate threads.concurrently_,mapConcurrently_,forConcurrently_, andreplicateConcurrently_functions, which discard the result of the non-_ version.
- New instances:
Semigroupinstance forConcurrentlywhen built with base 4.9.Monoidinstance forConcurrently.
Control.Monad.Conc.Class
- The
mask_anduninterruptibleMask_functions from Control.Monad.Catch are now re-exported.
Changed
- The
canceland thewithAsyncfunctions now block until theAsyncaction terminates, to match changes in the main async package.
Miscellaneous
- Every definition, class, and instance now has a Haddock “@since” annotation.
1.1.1.0
- Date 2017-03-04
- Git tag concurrency-1.1.1.0
- Hackage https://hackage.haskell.org/package/concurrency-1.1.1.0
Miscellaneous
- The async-dejafu package has been pulled into this package as the Control.Concurrent.Classy.Async module. async-dejafu is now deprecated.
1.1.0.0
- Date 2017-02-21
- Git tag concurrency-1.1.0.0
- Hackage https://hackage.haskell.org/package/concurrency-1.1.0.0
Control.Monad.Conc.Class
- The
MonadConcclass now definestryReadMVar, a non-blocking version ofreadMVarakin totryTakeMVar. - The
MonadConcclass no longer defines_concMessage, there is no alternative provided, it is just gone.
1.0.0.0
- Date 2016-09-10
- Git tag concurrency-1.0.0.0
- Hackage https://hackage.haskell.org/package/concurrency-1.0.0.0
Initial release. Go read the API docs.