daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. init(rdr, false);
  2. init (wrt, false);
  3. int readcount = 0;
  4.  
  5. writer()
  6. {
  7. while(true){
  8.     wait(wrt);
  9.     /* write */
  10.     ....
  11.     signal(wrt)
  12.  }
  13. }
  14.  
  15. reader()
  16. {
  17.  while (true)
  18.  {
  19.     wait(rdr);
  20.     readcount++;
  21.     if (readcount == 1)
  22.         wait(wrt)
  23.     signal(rdr);
  24.     /* read */
  25.     ...
  26.     wait(rdr);
  27.     readcount--;
  28.     if (readcount == 0)
  29.         signal(wrt);
  30.     signal(rdr);
  31.  }
  32. }
  33.  
  34.  
  35.  
  36. reader()
  37. {
  38.  while (true)
  39.  {
  40.     while (wrt == true)
  41.         no-op;
  42.     wait(rdr);
  43.     readcount++;
  44.     if (readcount == 1)
  45.         wait(wrt)
  46.     signal(rdr);
  47.     /* read */
  48.     ...
  49.     wait(rdr);
  50.     readcount--;
  51.     if (readcount == 0)
  52.         signal(wrt);
  53.     signal(rdr);
  54.  }
  55. }
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