rwlocks.pl -- Read/write locks
This library implements read/write locks on top of with_mutex/2. Read/write locks are synchronization objects that allow for multiple readers or a single writer to be active.
- with_rwlock(+LockId, :Goal, +ModeSpec)
- with_rwlock(+LockId, :Goal, +ModeSpec, +Options)
- Run Goal, synchronized with LockId in ModeSpec. ModeSpec is one of
read
,write
,read(Priority)
orwrite(Priority)
. The defaultread
priority is 100 and the defaultwrite
priority is 200. These values prioritize writers over readers. Goal may start if- If there is no goal waiting with higher priority and
- It is a read goal and no write goal is running or
- It is a write goal and no other goal is running.
If Goal may not start immediately the thread waits using thread_wait/2. The Options
timeout
anddeadline
are passed to thread_wait/2. If the time limit is exceeded an exception is raised.Read/write locks are widely critized for their poor behaviour on several workloads. They perform well in scenarios where read operations take long, and write operations are relatively fast and occur only occasionally. Transactions, as implemented by transaction/1,2 are often a better alternative.
This predicate uses a normal mutex and a flag with the same name. See with_mutex/2 and flag/3. Neither the mutex nor the flag should be used directly.
- If there is no goal waiting with higher priority and
Re-exported predicates
The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
- with_rwlock(+LockId, :Goal, +ModeSpec)
- with_rwlock(+LockId, :Goal, +ModeSpec, +Options)
- Run Goal, synchronized with LockId in ModeSpec. ModeSpec is one of
read
,write
,read(Priority)
orwrite(Priority)
. The defaultread
priority is 100 and the defaultwrite
priority is 200. These values prioritize writers over readers. Goal may start if- If there is no goal waiting with higher priority and
- It is a read goal and no write goal is running or
- It is a write goal and no other goal is running.
If Goal may not start immediately the thread waits using thread_wait/2. The Options
timeout
anddeadline
are passed to thread_wait/2. If the time limit is exceeded an exception is raised.Read/write locks are widely critized for their poor behaviour on several workloads. They perform well in scenarios where read operations take long, and write operations are relatively fast and occur only occasionally. Transactions, as implemented by transaction/1,2 are often a better alternative.
This predicate uses a normal mutex and a flag with the same name. See with_mutex/2 and flag/3. Neither the mutex nor the flag should be used directly.
- If there is no goal waiting with higher priority and