|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectse.lth.cs.realtime.semaphore.MutexSem
A Semaphore with special support for MUTual EXclusion. Basically,
this is equivalent with other semaphores, such as
CountingSem
or BinarySem
, except for:
SemViolation
error being thrown.
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, which should provide priority inheritance
(even if priorities are not strictly obeyed).
License
,
Semaphore
,
MutexSem
,
CountingSem
,
MultistepSem
,
SemInterrupted
,
SemViolation
Constructor Summary | |
MutexSem()
Creates a new MutexSem with the internal (boolean)
access flag set to true. |
Method Summary | |
void |
give()
Sets the mutex to its unoccupied state and releases the first-in-queue blocked thread, if any. |
void |
take()
Causes the calling thread to block until the mutex semaphore can be taken. |
boolean |
tryTake(long timeout)
Try to take the semaphore but give up after a certain time. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MutexSem()
MutexSem
with the internal (boolean)
access flag set to true. To enforce the rule of calling take
before give, this is the only way a MutexSem
can be
created.
Method Detail |
public void give()
give
in interface Semaphore
SemViolation
- if the calling thread tries
to give away a lock that it does not own, that is, if the
semaphore has not been taken first.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
timeout
- specifies the time after which the calling
thread should be unblocked and return even if the semaphore was
not taken. The time of the actual return depends on the
underlaying OS/VM/scheduler etc., just like for the calls
without a timeout argument.
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: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |