Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can just set the turn to true or false to represent reading or writing is done #27

Closed
haicoder opened this issue Apr 10, 2021 · 1 comment

Comments

@haicoder
Copy link

According to the implementation.

Enqeue:

  • Acquire next write ticket from head.
  • Wait for our turn (true) to write slot (ticket % capacity).
  • Set turn = false to inform the readers we are done writing.

Dequeue:

  • Acquire next read ticket from tail.
  • Wait for our turn (false) to read slot (ticket % capacity).
  • Set turn = true to inform the writers we are done reading.

Dose this work?

Thank you.

@rigtorp
Copy link
Owner

rigtorp commented Apr 21, 2021

No! If there are more threads than there are slots in the queue it wouldn't work. So best to avoid that limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants