package monitor
- Alphabetic
- Public
- All
Type Members
-
class
AbstractMonitor
extends debug.REGISTRY.Debuggable
Abstract precursor of monitor implementations that use
jdk.util.concurrent.lock
classes.Abstract precursor of monitor implementations that use
jdk.util.concurrent.lock
classes. Iffair
is true then the lock is first-come first-served. Under heavy contention this can be useful, but it appears to impose a penalty of (around) a factor of 10 in the elapsed time to acquisition of the lock.If a monitor is registered with the debugger its state will be shown in a debugger snapshot if its lock is owned (or awaited) at the time of the snapshot. This can be helpful for in-extremis debugging.
Objects that use one of these monitor as a source of
Condition
s in their implementation must themselves register with the debugger and must themselves implement the debugger'shasState/showState/getWaiting/
protocol.The following is an implementation of a one-slot buffer using two condition queues so that multiple producer (consumer) processes can invoke put (get).
class MonitorSlot[T] extends Slot[T] { private [this] val monitor = new Monitor private [this] var value: T = _ private [this] var empty = true private [this] val isEmpty, isNonEmpty = monitor.newCondition def put(v: T) = monitor withLock { while (!empty) isEmpty.await() value = v; empty = false isNonEmpty.signal() } def get: T = monitor withLock { while (empty) isNonEmpty.await() val result = value; empty = true isEmpty.signal() return result } }
The following is an implementation of a one-slot buffer using just a single queue. Multiple producer (consumer) processes can still invoke put (get), but note the use of the (less efficient under load)
signalAll
method.class MonitorSlot2[T] extends Slot[T] { private [this] val monitor = new Monitor private [this] var value: T = _ private [this] var empty = true private [this] val waiting = monitor.newCondition def put(v: T) = monitor withLock { while (!empty) waiting.await() value = v; empty = false waiting.signalAll() } def get: T = monitor withLock { while (empty) waiting.await() val result = value; empty = true waiting.signalAll() return result } }
-
class
FairMonitor
extends AbstractMonitor
A class that provides re-entrant first-come-first-served locking and condition variables
A class that provides re-entrant first-come-first-served locking and condition variables
- See also
io.threadcso.monitor.AbstractMonitor for usage
-
class
Monitor
extends AbstractMonitor
A class that provides re-entrant locking and condition variables
A class that provides re-entrant locking and condition variables
- See also
io.threadcso.monitor.AbstractMonitor for usage
Value Members
- object FairMonitor
- object Monitor