Adri C.S.
Adri C.S.

Reputation: 3007

About tbb tasks

When working with tasks, for example with this:

class MyTask: public tbb::task {
  private:
    int x;
  private:
    void DoSomething(...){...} // Invoked only inside execute
    void DoMore(...){...}  // Invoked only inside execute
  public:
    MyTasks(...){...}
    tbb::task* execute(){...}
};

Once the task is running, is it possible to execute concurrently DoSomething() or DoMore() or those methods can only be invoked by the thread that started the execution of the task?.

I read that TBB allows job stealing, but what it steals? Does it steal a piece of data, compute it and return the result to the main thread or could it be possible for the stealing to execute the private methods?

Sorry If my question isn't clear!

Thanks.

Upvotes: 1

Views: 453

Answers (1)

Alexey Kukanov
Alexey Kukanov

Reputation: 12784

TBB steals a task, i.e. an instance of a class derived from tbb::task. The method execute() of the task is then invoked. This method is executed by a single thread, but it can produce new tasks that are put into thread's local task pool, and can be stolen by other threads.

In your case, the private methods that are only called by execute() will not run concurrently.

Upvotes: 2

Related Questions