Signalling using Semaphores
Signalling using Semaphores
The demonstration program has two threads: Thread A signals the semaphore using up() and Thread B waits for the semaphore using down().
Demo
class Signaller
implements Runnable {
Semaphore sema_;
Signaller(Semaphore s)
{ sema_ = s; }
public void run() {
while(true) {
for(int i=0;i<60; i++)
DisplayThread.rotate();
sema.up();
}}}
class Waiter
implements Runnable {
Semaphore sema_;
Waiter(Semaphore s)
{ sema_ = s; }
public void run() {
while(true) {
sema_.down();
for(int i=0;i<10; i++)
DisplayThread.rotate();
}}}