class CountingSemaphore extends debug.REGISTRY.Debuggable with Semaphore
A counting semaphore which maintains a virtual/conceptual set
of permits. Each acquire
waits if necessary until a permit
is available, and then removes it from the set. Each release
adds a permit, potentially causing a waiting acquire
to
return.
If the semaphore is fair
the semaphore will (under contention)
guarantee first-in first-out acquisition of permits (by default
it is not fair). Fairness can impose considerable delays.
No actual permit objects are involved; the semaphore just keeps
a count of the number available
, which may initially be
negative.
A thread that release
s a permit need not have acquired one
previously.
This implementation delegates to
java.util.concurrent.Semaphore
.
A CountingSemaphore
can be registered with the debugger.
- Deprecated
Use io.threadcso.semaphore.CountingSemaphore instead unless you absolutely need the fairness parameter.
- Alphabetic
- By Inheritance
- CountingSemaphore
- Semaphore
- Debuggable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
CountingSemaphore(available: Int, name: String = null, fair: Boolean = false, _register: Boolean = false)
- Deprecated
Use io.threadcso.semaphore.CountingSemaphore instead unless you absolutely need the fairness parameter.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
acquire(): Unit
Wait until a token is free, then remove it from the collection.
Wait until a token is free, then remove it from the collection.
- Definition Classes
- CountingSemaphore → Semaphore
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
cancel(): Unit
Optional: cancel all threads waiting to acquire the semaphore: defined only in io.threadcso.semaphore.BooleanSemaphore and io.threadcso.semaphore.CountingSemaphore
Optional: cancel all threads waiting to acquire the semaphore: defined only in io.threadcso.semaphore.BooleanSemaphore and io.threadcso.semaphore.CountingSemaphore
- Definition Classes
- CountingSemaphore → Semaphore
-
def
cancelled(): Boolean
True if the most recent semaphore acquisition was cancelled
True if the most recent semaphore acquisition was cancelled
- Definition Classes
- CountingSemaphore → Semaphore
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
down(): Unit
same as acquire
same as acquire
- Definition Classes
- Semaphore
- Annotations
- @inline()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
getWaiting: Seq[Thread]
Return an (approximate) list of the threads waiting to acquire a token from this semaphore.
Return an (approximate) list of the threads waiting to acquire a token from this semaphore. Intended for use only by diagnostic components.
- Definition Classes
- CountingSemaphore → Semaphore → Debuggable
-
def
hasState: Boolean
This object has a state worth showing right now: false if showState will do no output.
This object has a state worth showing right now: false if showState will do no output.
- Definition Classes
- Debuggable
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
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
- var name: String
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- def reInitialize(): Unit
-
def
register(): Unit
Register this object
Register this object
- Definition Classes
- Debuggable
-
def
release(): Unit
Release a token that may (but need not) have previously been acquired.
Release a token that may (but need not) have previously been acquired.
- Definition Classes
- CountingSemaphore → Semaphore
-
def
remaining(): Int
Approximation to the number of acquires that could now succeed without having to wait.
Approximation to the number of acquires that could now succeed without having to wait. Intended for use only by diagnostic components.
- Definition Classes
- Semaphore
-
def
showState(out: PrintWriter): Unit
Show the current state of this object: default uses
toString
Show the current state of this object: default uses
toString
- Definition Classes
- CountingSemaphore → Debuggable
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- CountingSemaphore → AnyRef → Any
-
def
tryAcquire(wait: Long): Boolean
Optional: Wait until a token is free, or until
timeoutNS
nanoseconds have elapsed.Optional: Wait until a token is free, or until
timeoutNS
nanoseconds have elapsed. In the former case acquire a token and return true; in the latter case return false.- Definition Classes
- CountingSemaphore → Semaphore
-
def
unregister(): Unit
Unregister this object
Unregister this object
- Definition Classes
- Debuggable
-
def
up(): Unit
same as release
same as release
- Definition Classes
- Semaphore
- Annotations
- @inline()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
withDebugger[T](condition: Boolean)(body: ⇒ T): T
Conditionally
register
this object with the debugger only for the duration of the evaluation ofbody
.Conditionally
register
this object with the debugger only for the duration of the evaluation ofbody
. To be used as a last resort for the exasperated CSO toolkit debugger.- Definition Classes
- Debuggable