fvars-1.0.0.0: Fast Mutable Vars

Copyright(c) Erick Gonzalez 2019
LicenseBSD3
Maintainererick@codemonkeylabs.de
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.FVar

Description

This library implements an FVar or fast Var. The idea is that it allows concurrent readers to access shared data without locking, but the moment a writer performs a write it gets exclusive access to the var. If there are readers currently accesing the data, it waits until they complete the operation, blocks any further reads and then it performs the write. Once it is done, it reenables the stalled readers and lockless operation continues.

Synopsis

Documentation

modifyFVar :: (MonadMask m, MonadIO m) => FVar a -> (a -> m (a, b)) -> m b Source #

Modify the data inside an FVar. Write access during execution of the function provided will be exclusive so other writes or reads will be stalled until the call to modifyFVar is completed

newFVar :: MonadIO m => a -> m (FVar a) Source #

Creates a new FVar containing the data provided. Note that unlike MVars, an FVar can not be empty. This is to avoid complications stalling lock-less reads in that case. There is of course nothing stopping you from storing a value wrapped in a Maybe to account for a similar usage pattern.

readFVar :: (MonadMask m, MonadIO m) => FVar a -> (a -> m b) -> m b Source #

Access an FVar for reading using the provided function. Access is not exclusive, so multiple threads would be allowed to access the data simultaneously. Note that there is actually nothing in principle preventing one from mutating shared data during this access but in doing so you would be violating the contract in this API and thus integrity could not be guaranteed, so you must refrain from doing so and truly only perform read accesses to the shared data

data FVar a Source #

An FVar (a.k.a. eff-var or Fast Var) is a synchronising variable which allows concurrent simultaneous read access without the need for locking. Write access is however exclusive and causes all other operations to stall until the write is completed and lockless operation can continue.

Instances
Eq (FVar a) Source # 
Instance details

Defined in Control.Concurrent.FVar

Methods

(==) :: FVar a -> FVar a -> Bool #

(/=) :: FVar a -> FVar a -> Bool #