Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. first condition:
  2. Thread 1 Waits
  3. Thread 2 Notifies
  4.  
  5. second condition:
  6. Thread 2 Notifies
  7. Thread 1 Should not wait and continue normal execution.
  8.  
  9. Thread 1:
  10. lock(x);
  11. if(!signaled)
  12. {
  13. unlock(x); // ****************************
  14. // still small gap, how to avoid?
  15. cv.wait();
  16. signaled = false;
  17. }
  18. else unlock(x);
  19.  
  20. Thread 2:
  21. lock(x);
  22. signaled = true;
  23. cv.notify();
  24. unlock(x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement