- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to separate spawn_root_and_wait() into 2 calls: spawn and wait. I need to do some processing in the main thread while my tasks are working.
How can I do this?
...Matt
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to separate spawn_root_and_wait() into 2 calls: spawn and wait. I need to do some processing in the main thread while my tasks are working.
How can I do this?
...Matt
Create 2 root tasks: first is your current root task, and second is your processing that you need to do concurrently with tasks. Spawn both tasks simultaneously - there is spawn_root_and_wait() overload that accepts a list of tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Create 2 root tasks: first is your current root task, and second is your processing that you need to do concurrently with tasks. Spawn both tasks simultaneously - there is spawn_root_and_wait() overload that accepts a list of tasks.
The work that I need to do must be done on the UI thread, so I cannot spawn off a second thread to do this work (I tried this solution already).
Analternative is to create custom messages to be posted from worker threads. However, that would require a significant amount of additional work. If I can separate the spawn and wait calls, then all I need is 10 lines of code to marshall info between the worker threads and the UI thread: much simpler solution.
For now, I'm creating a worker thread (non-tbb) that spawns the real worker tasks. While I wait for the non-tbb thread to complete, I do the work I need on the UI thread. Not the most elegant, but it works. Having separate spawn and wait calls (like we do when we're already inside a task) would simplify things greatly.
...Matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#include "tbb/task_scheduler_init.h"
#include "tbb/task.h"
#include
class OtherThing: public tbb::task {
/*override*/ task* execute() {
for( volatile int i=0; i<50000000; ++i )
if( i%10000000==0 )
printf("Doing thing off to siden");
return NULL;
}
};
class DoTaskOffToSide {
tbb::empty_task* root;
public:
DoTaskOffToSide() {
root = new( tbb::task::allocate_root() ) tbb::empty_task;
// 2 = 1 for child and 1 for wait
root->set_ref_count(2);
tbb::task& child = *new( root->allocate_child() ) OtherThing;
root->spawn(child);
}
~DoTaskOffToSide() {
root->wait_for_all();
root->destroy(*root);
}
};
int main() {
tbb::task_scheduler_init init;
{
DoTaskOffToSide s;
for( volatile int i=0; i<50000000; ++i )
if( i%10000000==0 )
printf("Doing main thing on original threadn");
}
printf("Donen");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In '1 thread' setup all the work must be done in the thread that execute spawn_root_and_wait(). There must be NO DIFFERENCE for you, and there must be NO DEADLOCKS if there is no worker-threads (if you are doing all correctly). I can suggest that you describe you algorithm and setup in more detail - infrequent deadlocks suggest that you have some logic error in your program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Occasional deadlocks CANNOT be induced by TBB scheduler (if there is no serious errors), only by your program logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are using separate non-tbb thread to wait for tbb, then why your main thread is not processing messages? It must spawn separate thread and return to message processing, no? And PostMessage() must do the work.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page