rigtorp/MPMCQueue

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

haicoder opened this issue · 1 comments

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.

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