Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReadWriteLock {
- //register Reader(Thread t)
- //readLock()
- //readUnLock()
- //writeLock()
- //writeUnLock()
- // set <long> readers = new HashSet<>();
- // set <long> whoEntered = new HashSet<>();
- // set <long> whoLeft = new HashSet<>();
- //boolean writeWait = false;
- //public synchronized void registerReader(Thread t) {
- //
- // readers.add(t.getId());
- // }
- //public synchronized void unRegisterReader(Thread t) {
- //
- // readers.remove(t.getId());
- // }
- //public synchronized void lockRead() throws inter...
- //long id = getId();
- //while(whoEntered.contains(id) || writerWait == false) {wait();}
- //whoEntered.add(id);
- //public synchronized void unLockRead()
- // {long id = getId();
- //whoLeft.add(id);
- //if (whoLeft.containsAll(readers) &&
- // whoLeft.equals(whoEntered)) { writerWait = false;}
- // notifyAll();
- //public synchronized void lockWrite() throw inter {...
- // while(writerWait) {wait();}
- // writeWait=true;}
- //public synchronized void unLockWrite() {...
- // whoEntered.clear();
- // whoLeft.clear();
- // notifyAll();}
- //private long getId() {return Thread.currentThread().getId(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement