Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public class ReadWriteLock {
  2.  
  3. //register Reader(Thread t)
  4. //readLock()
  5. //readUnLock()
  6. //writeLock()
  7. //writeUnLock()
  8. // set <long> readers = new HashSet<>();
  9. // set <long> whoEntered = new HashSet<>();
  10. // set <long> whoLeft = new HashSet<>();
  11. //boolean writeWait = false;
  12.  
  13. //public synchronized void registerReader(Thread t) {
  14. //
  15. // readers.add(t.getId());
  16. // }
  17. //public synchronized void unRegisterReader(Thread t) {
  18. //
  19. // readers.remove(t.getId());
  20. // }
  21.  
  22.  
  23. //public synchronized void lockRead() throws inter...
  24. //long id = getId();
  25. //while(whoEntered.contains(id) || writerWait == false) {wait();}
  26. //whoEntered.add(id);
  27.  
  28.  
  29. //public synchronized void unLockRead()
  30. // {long id = getId();
  31. //whoLeft.add(id);
  32. //if (whoLeft.containsAll(readers) &&
  33. // whoLeft.equals(whoEntered)) { writerWait = false;}
  34. // notifyAll();
  35.  
  36.  
  37. //public synchronized void lockWrite() throw inter {...
  38. // while(writerWait) {wait();}
  39. // writeWait=true;}
  40.  
  41.  
  42. //public synchronized void unLockWrite() {...
  43. // whoEntered.clear();
  44. // whoLeft.clear();
  45. // notifyAll();}
  46. //private long getId() {return Thread.currentThread().getId(); }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement