concurrentqueue icon indicating copy to clipboard operation
concurrentqueue copied to clipboard

In some cases, the order of values retrieved by calling try_dequeue does not match the order in which the values were placed by enqueue.

Open wangxm7237 opened this issue 7 months ago • 6 comments

Call Sequence: 1 call to enqueue, inserting value 4. 2.After a 50ms interval, second call to enqueue, inserting value 0. 3.Within less than 1ms, first call to try_dequeue, retrieving value 0. 4Within less than 1ms, second call to try_dequeue, retrieving value 4.

The first enqueue operation (ImplicitProducer::enqueue) inserts value 4 into an instance (e.g., 0x0000007f28001920). The second enqueue operation (ImplicitProducer::enqueue) inserts value 0 into a different instance (e.g., 0x0000007f2c0103a0). The first try_dequeue operation selects the instance (0x0000007f2c0103a0) based on a "best" scoring mechanism and retrieves value 0. The second try_dequeue operation selects the instance (0x0000007f28001920) based on the same mechanism and retrieves value 4.

Is there a solution to ensure that the dequeue order matches the enqueue order in this scenario?

Image

We checked the code and appended the log and found

Image For data 0 and data 4, the bestSize calculation is 1, resulting in the wrong order of data when retrieving.

wangxm7237 avatar Jun 15 '25 13:06 wangxm7237