Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

is it reasonable to use thread_bound_filter

Xingjing_Lu
Beginner
520 Views

The use case is:

  There are global shared buffer among different stages, and I employ flag array to control accesses  to these buffers from different stages, which are usually the fi and fi+1 (producer and consumer)。

  tbb::atomic<int> BufIsFull;

tbb::atomic<unsinged int> WriteToBufNum, ReadToBufNum;

  Now, because the filter(serial) can be executed by different threads on different items, so I  have to make these flag array and index variable to these array are tbb::atomic(WriteToBufNum, ReadToBufNum).

I think, if I use thread_bound_filter, I don't need to declare WriteToBufNum as atomic type, which may reduce the overhead.

 

My questions are:

1) Can I have multi-thread_bound_filter in a pipeline?

2)in the example from manual, g is a thread_bound_filter

while (g.process_item()!=thread_bound_filter::end_of_stream)
continue;

t.join();

If have multi-filter, likeg,  g1, g2, g3, do I have to do below? And Do I need to fork thread for each thread_bound_filter?

while (g.process_item()!=thread_bound_filter::end_of_stream && g1process_item()!=thread_bound_filter::end_of_stream && ......)
continue;

Thanks in advance!

Xingjing Lu

 

 

0 Kudos
1 Solution
Alexey-Kukanov
Employee
520 Views

1) Yes, you may have more than one thread-bound filter in a pipeline.

2) You may process each thread-bound filter in its own thread, or you may process all in the same thread. In the latter case, yes you will need to query every filter in the loop. But it should be 

while (g1.process_item()!=end_of_stream || g2.process_item()!=end_of_stream /* || more the same way */ )
    continue;

With &&, the loop would finish as soon as any single filter reached end_of_stream, possibly leaving unprocessed items in the pipeline.

View solution in original post

0 Kudos
2 Replies
Alexey-Kukanov
Employee
521 Views

1) Yes, you may have more than one thread-bound filter in a pipeline.

2) You may process each thread-bound filter in its own thread, or you may process all in the same thread. In the latter case, yes you will need to query every filter in the loop. But it should be 

while (g1.process_item()!=end_of_stream || g2.process_item()!=end_of_stream /* || more the same way */ )
    continue;

With &&, the loop would finish as soon as any single filter reached end_of_stream, possibly leaving unprocessed items in the pipeline.

0 Kudos
Xingjing_Lu
Beginner
520 Views

Thanks.

0 Kudos
Reply