Protecting read/write
public class ReadWritePriority2
{
public synchronized void startRead()
{
while(writers > 0 || writersWaiting > 0)
wait();
readers++;
readList.add(Thread.currentThread());
}
public synchronized void endRead()
{
readers--;
readList.remove(Thread.currentThread());
notifyAll();
}
Previous slide
Next slide
Back to first slide
View graphic version