4

The Intel Thread Building Blocks library includes a concurrent_queue container.

Unfortunately, digging around on the internet has yet to yield an example of a concurrent_queue being used in a parallel manner by the TBB library.

Could someone provide an example of the queue at work with several threads simultaneously popping items off and pushing items on until the queue at last is empty?

Richard
  • 56,349
  • 34
  • 180
  • 251
  • Create type `Foo`; instantiate `concurrent_queue` globally; write code for two threads, one loops `n` times pushing `new Foo`, then pushes `nullptr`; the other loops infinitely calling `try_pop()`, breaks the infinite loop when it pops `nullptr` (but don't exit before pushing `nullptr` back so others can see it). In `main()`, launch both threads (multiple times if you want), then join them. Should be enough to get you started. – DanielKO Aug 21 '13 at 20:42

1 Answers1

2

Look for "concurrent_queue" in the Intel Threading Building Blocks Design Patterns manual and you will find some examples.

Arch D. Robison
  • 3,829
  • 2
  • 16
  • 26