Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Queue:
- signed int size
- unsigned int consumer_index
- unsigned int producer_index
- unsigned int capacity
- consumer:
- atomic dec size
- atomic read local_size := size
- if size < 0:
- atomic inc size
- ret Err
- else:
- atomic inc consumer_index
- read result := queue[consumer_index]
- ret Success(result)
- producer:
- atomic inc size
- atomic read local_size := size
- if size > capacity:
- atomic dec size
- ret Err
- else:
- atomic inc producer_index
- put queue[consumer_index] := result
- ret Success
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement