- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a tbb application in that looks like this:
int main() {
graph g;
input_node<Msg> input(g);
function_node<Msg,int> long_work_node( g, unlimited, [] {
... do work, task cannot be broken up ...
graph_result.push(result_value);
return 0;
});
make_edge( input, long_work_node );
input.activate()
// try getting output from graph_output
int result;
while( ... running ... ) {
bool got_result = graph_result.try_pop(result);
if(got_result) {
... use results ...
} else {
... wait and do nothing ...
}
}
g.wait_for_all();
return 0;
}
A lot of the time the main thread is spinning and doing nothing. I would like the main thread to "moonlight" and participate in the graph, but only temporarily (i.e., I don't want to wait until the graph to finish completely).
Are there simple code patterns to do what I'm trying to? How do I achieve this?
Any help appreciated!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @JonCz ,
Flow graph should use the master thread for node computations. How have you determined that the main thread is just spinning? Have you used Vtune? You could also create a task_group inside the node.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @JonCz ,
As I said above, the main thread should work in general (for the flow graph). However, if you're trying to add your own internal queue and wait on it (at least it looks like your intent) --
bool got_result = graph_result.try_pop(result);
if(got_result) {
... use results ...
} else {
... wait and do nothing ...
}
please provide more details regarding this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To temporarily allow the main thread to participate in a flow graph:
1. **Suspend** the flow graph execution.
2. Execute main thread tasks.
3. **Resume** flow graph execution afterward.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page