daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top