SimpleCxxLib packageclass Locksynchronized
macro described later in this interface.
| Constructor | |
| Initializes a lock, which is initially in the unlocked state. | |
| Methods | |
| Signals all threads waiting on the lock so that they wake up and recheck the corresponding condition. | |
Waits for some other thread to call signal on this lock. | |
| Statement | |
| Defines a critical section protected by the specified lock. | |
Lock();
Usage:
Lock lock;
void wait();
signal on this lock.
This call requires that the lock be held by the calling thread.
The effect of the wait method is to release the lock
and then wait until the desired signal operation occurs,
at which point the lock is reacquired and control returns from the
wait call. The wait method is typically
used inside a critical section containing a while loop
to check for a specific condition. The standard paradigm for using
the waitThread function looks like this:
synchronized (lock) {
while (conditional test) {
lock.wait();
}
... code to manipulate the locked resource ...
}
Usage:
lock.wait();
void signal();
Usage:
lock.signal();
synchronized (lock) ...
synchronized (lock) {
... statements in the critical section ...
}