1.. _When_Not_to_Use_Queues: 2 3When Not to Use Queues 4====================== 5 6 7Queues are widely used in parallel programs to buffer consumers from 8producers. Before using an explicit queue, however, consider using 9``parallel_for_each`` ``parallel_pipeline`` instead. These is often more 10efficient than queues for the following reasons: 11 12 13- A queue is inherently a bottle neck, because it must maintain 14 first-in first-out order. 15 16 17- A thread that is popping a value may have to wait idly until the 18 value is pushed. 19 20 21- A queue is a passive data structure. If a thread pushes a value, it 22 could take time until it pops the value, and in the meantime the 23 value (and whatever it references) becomes "cold" in cache. Or worse 24 yet, another thread pops the value, and the value (and whatever it 25 references) must be moved to the other processor. 26 27 28In contrast, ``parallel_pipeline`` avoids these bottlenecks. Because its 29threading is implicit, it optimizes use of worker threads so that they 30do other work until a value shows up. It also tries to keep items hot in 31cache. 32 33