Closed devinzhang91 closed 2 years ago
See the README. The final order between items that are enqueued by different threads/producers is not deterministic. Here, only the items enqueued to q2
by the same worker thread that enqueues -1 are guaranteed to be processed by the consumer thread.
To fix this example, consider having each worker thread enqueue -1 to q2
when done, and move the flag_cnt
logic into the consumer thread.
See the README. The final order between items that are enqueued by different threads/producers is not deterministic. Here, only the items enqueued to
q2
by the same worker thread that enqueues -1 are guaranteed to be processed by the consumer thread.To fix this example, consider having each worker thread enqueue -1 to
q2
when done, and move theflag_cnt
logic into the consumer thread.
Thank you for your reply , flag_cnt
has moved in q2
end detecttion, it works correctly.
Iuse two BlockingConcurrentQueue(q1,q2) to link producer ,workers, consumer. The model like this: 1 producer -> q1 -> 4 workers(consumer/producer) -> q2 -> 1 consumer But at the end of all thread is joined, q2 is not empty, I'm not sure if I'm using the wrong case. I use -1 in place of t the end signal. The end signal will shut down thread when workers /consumer received it. This code may need to be run several times before the error occurs.