Packages

  • package root
    Definition Classes
    root
  • package io

    This is the documentation for the ThreadCSO Library.

    This is the documentation for the ThreadCSO Library. Notable packages include:

    Definition Classes
    root
  • package threadcso

    The standard threadCSO API.

    The standard threadCSO API. Most modules using CSO will need only the declaration:

    import io.threadcso._

    The present version of the ThreadCSO library API is 1.2Rr (for some number r)

    The revision number (Rr) will change if bugs are corrected but the code remains consistent with the previous API. Its minor version number will change if there is a correction to the code that breaks consistency with the previous API. Its major version will change if there is a substantial change in the semantics of an important CSO construct.

    August 2017: changes 1.1 => 1.2

    • renaming of very many internal classes and packages
    • basic channel implementations are more efficient, in some case much more so
    • alternation reliability improved
    • debugger registration of alternations is no longer needed
    • home-grown semaphores can specify which component they are part of: this makes interpreting a stack backtrace very much easier
    • there is a flexible logging system that is compatible with the debugger

    April 2016: changes 1.0 => 1.1

    • Extended rendezvous read operator is now ?? (was ?)
    • Extended rendezvous read event notation is now =??=> (was =?=>>)
    • The notation inport ? f is now equivalent to f(inport?()) This makes for a tidier layout when the function f is an explicit functional expression.

    Feb 1 2017: changes 1.1R1 => 1.1R2

    • Removed dependencies on deprecated Java->Scala functions: replaced with .asJava
    @author Bernard Sufrin, Oxford
    $Revision: 286 $
    $Date: 2017-11-18 17:41:30 +0000 (Sat, 18 Nov 2017) $
    Definition Classes
    io
  • package monitor
    Definition Classes
    threadcso
  • AbstractMonitor
  • FairMonitor
  • Monitor
c

io.threadcso.monitor

AbstractMonitor

class AbstractMonitor extends debug.REGISTRY.Debuggable

Abstract precursor of monitor implementations that use jdk.util.concurrent.lock classes. If fair 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 Conditions in their implementation must themselves register with the debugger and must themselves implement the debugger's hasState/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
  }
}
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AbstractMonitor
  2. Debuggable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new AbstractMonitor(fair: Boolean, name: String = null)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  10. def getWaiting(condition: java.util.concurrent.locks.Condition): Seq[Thread]

    Approximate sequence of threads awaiting condition.

    Approximate sequence of threads awaiting condition. Yields an empty sequence if this monitor is owned by a thread other than the caller when it is called. The approximation is adequate only for use by a debugger.

    Annotations
    @inline()
  11. def getWaiting: Seq[Thread]

    The threads waiting for this lock.

    The threads waiting for this lock.

    Definition Classes
    AbstractMonitorDebuggable
  12. def hasState: Boolean

    Returns true iff it's owned or somebody's waiting (unlikely to be the latter without the former).

    Returns true iff it's owned or somebody's waiting (unlikely to be the latter without the former). Used only in the debugger to detect interesting monitor.

    Definition Classes
    AbstractMonitorDebuggable
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. val key: StateKey

    This object's key in the registry (if non-negative)

    This object's key in the registry (if non-negative)

    Definition Classes
    Debuggable
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def newCondition: java.util.concurrent.locks.Condition
    Annotations
    @inline()
  18. final def notify(): Unit
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  20. def register(): Unit

    Register this object

    Register this object

    Definition Classes
    Debuggable
  21. def showState(out: PrintWriter): Unit

    Output the state of an owned and awaited monitor

    Output the state of an owned and awaited monitor

    Definition Classes
    AbstractMonitorDebuggable
  22. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  23. def toString(): String

    The current state of the lock

    The current state of the lock

    Definition Classes
    AbstractMonitor → AnyRef → Any
  24. def tryLockFor[T](timeoutNS: Long)(body: ⇒ T)(otherwise: ⇒ T): T

    Try the lock for up to timeoutNS, and if it lock then evaluate body else evaluate otherwise

    Try the lock for up to timeoutNS, and if it lock then evaluate body else evaluate otherwise

    Annotations
    @inline()
  25. def unregister(): Unit

    Unregister this object

    Unregister this object

    Definition Classes
    Debuggable
  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. def waitingFor(condition: java.util.concurrent.locks.Condition): Boolean

    Approximate answer to the question are any threads awaiting condition? Yields false if the monitor is owned by a thread other than the caller when it is called.

    Approximate answer to the question are any threads awaiting condition? Yields false if the monitor is owned by a thread other than the caller when it is called. The approximation is adequate only for use by a debugger.

    Annotations
    @inline()
  30. def withDebugger[T](condition: Boolean)(body: ⇒ T): T

    Conditionally register this object with the debugger only for the duration of the evaluation of body.

    Conditionally register this object with the debugger only for the duration of the evaluation of body. To be used as a last resort for the exasperated CSO toolkit debugger.

    Definition Classes
    Debuggable
  31. def withLock[T](body: ⇒ T): T

    Evaluate body with the lock set; and then unset the lock.

    Evaluate body with the lock set; and then unset the lock. The lock is unset even if body throws an exception.

    Annotations
    @inline()

Inherited from debug.REGISTRY.Debuggable

Inherited from AnyRef

Inherited from Any

Ungrouped