Threading.Data.RWLock
- Package
- purescript-threading
- Repository
- cakekindel/purescript-threading
A RWLock allows threads to share mutable state.
Any number of threads can concurrently read the state, when there isn't a thread with write access.
Get write access with lockWrite
or tryLockWrite
,
or read access with lockRead
or tryLockRead
.
(try)lockWrite
returns a WriteGuard
, which guarantees
no other threads have read or write access until it is released.
(try)lockRead
returns a ReadGuard
, which guarantees
no threads have write access until it is released.
#RWLock Source
data RWLock a
A Read-Write lock
Ensures that there can be at most 1 thread with write access to the data contained in the RWLock, or any number of concurrent readers.
#lockWrite Source
lockWrite :: forall a. RWLock a -> Aff (WriteGuard a)
Acquire a write-access lock to the data contained in the RWLock.
If another thread holds a ReadGuard
or WriteGuard
,
this will block until the data is writable.
#tryLockWrite Source
tryLockWrite :: forall a. RWLock a -> Aff (Maybe (WriteGuard a))
Acquire a write-access lock to the data contained in the RWLock.
If another thread holds a ReadGuard
or WriteGuard
,
this will return Nothing.
#tryLockRead Source
tryLockRead :: forall a. RWLock a -> Aff (Maybe (ReadGuard a))
Acquire a read-access lock to the data contained in the RWLock.
If another thread holds a WriteGuard
,
this will return Nothing.
#Locked Source
data Locked
The lock state of the RWLock
Constructors
Unlocked
LockedWriting
There is a writer, and the RWLock is not currently readable or writable.
LockedReading
There is at least one reader, and the RWLock is not currently writable.
Instances
#RWLockGuard Source
class RWLockGuard :: (Type -> Type) -> Constraint
class RWLockGuard g where
Typeclass implemented by WriteGuard
and ReadGuard
allowing a common release
+ read
function (as opposed
to releaseRead
, releaseWrite
, etc.)
There are no readers or writers.