Copyright | (c) Erick Gonzalez 2019 |
---|---|
License | BSD3 |
Maintainer | erick@codemonkeylabs.de |
Safe Haskell | None |
Language | Haskell2010 |
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.
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
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
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.