c++ - which one faster concurrent_queue<> vs mutex-ed queue<> during iteration -


suppose want iterate item in queue implemented using concurrent_queue<> , std:queue<>.

since on concurrent_queue<> there no iterator, can think need try_pop() , push() until pop-ed , re-push-ed items in concurrent_queue<>.

which 1 more efficient in multithreaded condition?, doing that, or use iterator of queue<> , lock using critical section or other mutex.

i know test , benchmark answer question, need know reason why 1 should faster other.

if you're in multithreaded environment , push/pop queue check it, won't other threads see imprecise data if context-switch between pop , push operation? , thread might push object off, first thread miss it... etc.

it's complicated, fraught race conditions. you'd have lock on queue iteration guarantee data accuracy.

at point, question becomes: faster lock on queue , use iterator, or lock on queue , repeatedly pop/push? think can guess better option here :-)


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -