concurrent_queue - accessing the first element without popping it out

concurrent_queue - accessing the first element without popping it out

I am using TBB concurrent_queue class. It meets my needs except that I need to access the first element before popping it out of the queue (or put it back at front). As I understand from the document, one can't access first element or can't insert at the front like std:deque.

Any help on how to achieve this while maintaining concurrency as far as possible. I only need to access the front element and need to pop it out only if it meets some requirements - for example, to be consumed only after a particular time etc. 

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

Accessing elements in the queue without popping is potentially unsafe (because the element can be accessed while another thread pops/removes it). The ability pushing elements to the front will make the implementation inefficient. You may want to consider concurrent_hash_map that allows accessing elements without extraction. Or consider concurrent_ordered_map that allows concurrent traversal and preserve ordering by key (similar to the queue).

Alex,

You may want to consider concurrent_hash_map that allows accessing elements without extraction.

I am not sure how concurrent_hash_map will help. I need the queue behaviour (FIFO).

Or consider concurrent_ordered_map that allows concurrent traversal and preserve ordering by key (similar to the queue).

Is there anything like concurrent_ordered_map? I can't find it in the documentation. 

 

 

 

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya