Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. int r = 0;
  2. int w = 0;
  3.  
  4. read_lock(void)
  5. {
  6. r++;
  7. while( w != 0);
  8. }
  9.  
  10. read_unlock(void)
  11. {
  12. r—;
  13. }
  14. write_lock(void)
  15. {
  16. while( (r != 0) &&
  17. ( w != 0))
  18. w++;
  19. }
  20.  
  21. write_unlock(void)
  22. {
  23. w--;
  24. }
  25.  
  26. read_lock()
  27. // Critical Section
  28. read_unlock();
  29.  
  30. write_lock()
  31. // Critical Section
  32. write_unlock();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement