|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectse.lth.cs.realtime.semaphore.MultistepSem
Counting semaphore permitting increments and decrements that are
greater than one. Apart from the cases when the ordinary
CountingSem
can be used, a MultistepSem
is useful also in the following two situations:
take
twice
could result in a deadlock.
take
all need to be released by another signaling
thread. Not to require that the signaling thread
need to know the number of waiting threads, the method 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
,
CountingSem
,
BinarySem
,
MutexSem
Constructor Summary | |
MultistepSem()
Creates a new MultistepSem with the internal counter
initialized to 0. |
|
MultistepSem(int init)
Creates a new MultistepSem , initializing it to the
specified (possibly negative) number. |
Method Summary | |
void |
give()
The same as give(1) . |
void |
give(int howMany)
Increments the internal counter by the supplied number of steps and releases that many blocked thread, if any. |
void |
giveAll()
Increments the internal counter by the number of steps needed to release all blocked threads, if any. |
void |
take()
The same as take(1) . |
void |
take(int howMany)
Causes the calling thread to block until the counter represented by this semaphore assumes a value greater than defined by the argument, that is, until that many resources are available. |
boolean |
tryTake(long timeout)
Calling tryTake(maxtime) is the same as
calling tryTake(maxtime,1) . |
boolean |
tryTake(long timeout,
int howMany)
Try to atomically take one or several resources within a certain time. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MultistepSem()
MultistepSem
with the internal counter
initialized to 0.
public MultistepSem(int init)
MultistepSem
, initializing it to the
specified (possibly negative) number.
init
- the initial value of the number represented by
this semaphore.Method Detail |
public void give(int howMany)
give()
.
howMany
- the number of steps which the internal counter of
this semaphore should be incremented.
java.lang.IllegalArgumentException
- if the argument is not positive.CountingSem.give()
public void give()
give(1)
.
give
in interface Semaphore
public void giveAll()
give()
as many times as the (to the
caller unknown) number of threads waiting.
Note that even if all threads are released, a (high
priority) thread arriving after giveAll
but before
the last returning (previously blocked) thread can pass. That
is, the thread that has not returned will be blocked again, as
one would expect.
public void take(int howMany)
howMany
- the number of which the internal counter of
this semaphore must exceed before returning.
SemInterrupted
- (which is an error and not an exception)
if the calling thread has been interrupted before or during
blocking. You should not catch such an error, except for
special cases like handling system shut-down.
java.lang.IllegalArgumentException
- if the argument is not positive.public void take()
take(1)
.
take
in interface Semaphore
public boolean tryTake(long timeout, int howMany)
timeout
- specifies the time after which the take
operation should be given up.howMany
- the number of which the internal counter of
this semaphore must exceed before returning.
SemInterrupted
- (which is an error and not an exception)
if the calling thread has been interrupted before or during
blocking. Usually, you should not catch such an error.
java.lang.IllegalArgumentException
- if the second argument is not positive.public boolean tryTake(long timeout)
tryTake(maxtime)
is the same as
calling tryTake(maxtime,1)
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |