- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When working with tasks, for example with this:
[cpp]class MyTask: public tbb::task { private: int x; private: void DoSomething(...){...} // Used only inside execute void DoMore(...){...} // Used only inside execute public: MyTasks(...){...} tbb::task* execute(){...} };[/cpp]
Once the task is running, is it possible to execute concurrently DoSomething() or DoMore() by other threads 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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As documented, TBB threads may "steal" from each other's task pools when they have exhausted their own.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I wanted to know if TBB, when stealing work from the pool, could get the piece of work that uses those functions. If such thing is possible...
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The thread scheduler binds (assigns) an instance of an enqueued functor (and args) to a thread. That thread alone runs the functor to completion. Note that other threads may be bound (assigned) to run the additional instances of the functor concurrently.
The function call, represented by the functor and args, is run by the assigned thread, which can be thought of as the "master thread" for that instance of the function call. This function may contain additional parallel constructs, which may run concurrently using additional threads, but does not reassign the master thread of function relationship with the function's original starting thread. The original function "master thread" is the thread that completes the function call, represented by the functor and args. When (iif) the programmer creates non-joining thread constructs (e.g. asynchronous threads) within the function call, represented by the functor and args, it is the programmers responsibility to assure the lifetime of the function call is consistent with the expection requirement of the non-joining thread constructs spawned by that function.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another scenario would be to execute those operations before the task is spawned, or maybe a high-level task with lots of work in the descendants, but it still seems suspicious to me, because you probably don't want to have a task waiting for an application thread to finish. Try to express everything with tasks instead.
#3 "The function call, represented by the functor and args, is run by the assigned thread, which can be thought of as the "master thread" for that instance of the function call."
Just be careful with the terminology: for TBB, a master thread is any application thread that initiates TBB work, so a task may execute either on a master or on a worker.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is why I said:
::can be thought of as the "master thread" for that instance of the function call::
Use the complete context of what is being said.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure, but the semantic overload (such a "master" could be a TBB "worker") still seemed potentially confusing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A country has a leader, countries are divided into regions, a region has a leader, region is divided into smaller sections, those sections have a leader, etc...
Each division (recursion) has a leader (analog of a master thread).
The master thread of the application.
The master thread of the TBB thread pool (not necessisarily The Master Thread of the application)
The master thread of a task (not necessisarily The Master Thread of the TBB thread pool)
Jim
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page