Reputation: 79
can I use parallel_invoke to execute the same function multiple times
like I have function scan which traverse a string can I make the same multiple tasks operate on it.
Upvotes: 2
Views: 1218
Reputation: 34538
Yes, you can.
Alternatively you can use a task_group:
tbb::task_group g;
g.run(foo);
g.run(foo);
g.wait();
If you want to run it as often as you have CPU-cores, you can do it like this:
tbb::task_group g;
for(auto i = 0; i != tbb::tbb_thread::hardware_concurrency(); ++i) {
g.run(foo);
}
g.wait();
Upvotes: 1
Reputation: 27220
Yes, nothing will stop you, but you're responsible for determining whether those actions will cause race conditions or concurrency issues that will blow up your program.
Upvotes: 0