Assume a producer-consumer scenario. I have used a lock-free implementation of a fixed-capacity queue, so that:
- The number of items that can be held in the queue is limited.
- Producers/consumers can push/pop items to/from the queue directly without holding any lock.
Now, I'm considering how to synchronize the producers and consumers, so that producers are not busy try-pushing to a full queue, and consumers are not busy try-popping from an empty queue.
I thought about condition variable at first. But it seems to destroy the whole purpose of using a lock-free queue implementation.
Is polling (with interval) the only sensible way to go with a lock-free queue?