SHARE
TWEET

Untitled

a guest Jan 21st, 2020 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Queue:
  2.     signed int size
  3.     unsigned int consumer_index
  4.     unsigned int producer_index
  5.     unsigned int capacity
  6.  
  7. consumer:
  8.     atomic dec size
  9.     atomic read local_size := size
  10.  
  11.     if size < 0:
  12.         atomic inc size
  13.         ret Err
  14.     else:
  15.         atomic inc consumer_index
  16.         read result := queue[consumer_index]
  17.         ret Success(result)
  18.  
  19. producer:
  20.     atomic inc size
  21.     atomic read local_size := size
  22.  
  23.     if size > capacity:
  24.         atomic dec size
  25.         ret Err
  26.     else:
  27.         atomic inc producer_index
  28.         put queue[consumer_index] := result
  29.         ret Success
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