Fixed bug in example (count can become negative) -- see issue #252

This commit is contained in:
Cameron
2021-07-26 07:35:50 -04:00
parent 8e960d6971
commit a724a69854

View File

@@ -186,7 +186,7 @@ for (int i = 0; i != ProducerCount; ++i) {
for (int i = 0; i != ConsumerCount; ++i) {
consumers[i] = std::thread([&]() {
Item item;
while (promisedElementsRemaining.fetch_sub(1, std::memory_order_relaxed)) {
while (promisedElementsRemaining.fetch_sub(1, std::memory_order_relaxed) > 0) {
q.wait_dequeue(item);
consumeItem(item);
}