|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--se.lth.cs.realtime.semaphore.BinarySem
A Semaphore containing a boolean flag instead of a counter, to
support signaling in cases when waiting threads should not
catch up with successive missed calls of give
. Another
reason to use this class, mainly applicable to small compiled
applications, is efficiency when this type of semaphore is the
simplest and most optimized one for the particular type of OS/kernel.
Instead of a boolean flag, an implementation is free to use equivalent
solutions such as a counter with a maximum value of one, as
natively defined in some operating systems such as Windows.
The order of the awakenings of the threads which called
take
depends on the underlying OS and/or VM, but for
standard implementation in pure Java it will be the same as for the
wait/notify mechanism.
Semaphore
,
MutexSem
,
CountingSem
,
MultistepSem
,
SemInterrupted
Constructor Summary | |
BinarySem()
Creates a new BinarySem with
the internal (boolean) flag set to false. |
|
BinarySem(boolean access)
Creates a new BinarySem with
the internal (boolean) flag set to
the specified value. |
|
BinarySem(int count)
Creates a new BinarySem with the boolean
initialized in a way compatible with the constructors of
CountingSem . |
Method Summary | |
void |
give()
Sets the internal flag to true and releases the first-in-queue blocked thread, if any. |
void |
take()
Causes the calling thread to block until the boolean flag represented by this semaphore is set to true. |
boolean |
tryTake(long timeout)
Try to take the semaphore but give up after a certain time. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public BinarySem()
BinarySem
with
the internal (boolean) flag set to false.public BinarySem(boolean access)
BinarySem
with
the internal (boolean) flag set to
the specified value.public BinarySem(int count)
BinarySem
with the boolean
initialized in a way compatible with the constructors of
CountingSem
.Method Detail |
public void give()
give
in interface Semaphore
public void take()
take
in interface Semaphore
SemInterrupted
- (which is an error and not an exception)
if the calling thread has been interrupted before or during
blocking. The caller is not expected to catch it since
it indicated severe violation in the handling of resources,
concurrency, or time. Thus, you should not catch such an error,
except for special cases like handling an emergency stop.public boolean tryTake(long timeout)
tryTake
in interface Semaphore
SemInterrupted
- (which is an error and not an exception)
if the calling thread has been interrupted before or during
blocking. The caller is not expected to catch it since
it indicated severe violation in the handling of resources,
concurrency, or time. Thus, you should not catch such an error,
except for special cases like handling an emergency stop.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |