1

Is there a way to constraint nodes in the flow graph to run on the main thread? The case is that I have a big dependency graph where only some of the nodes can run on other threads. Instead of picking out the nodes that can run on other threads, I want to feed the entire graph to TBB and then mark some of the nodes to run on the main thread.

devotee
  • 127
  • 11
  • Currently, there is no such possibility to assign specific threads to the nodes. This is not only Flow Graph constraints but also TBB scheduler implementation which not guarantees that the TBB task will be executed on a specific thread. You could emulate what you need by having two graphs and one of them will be connected to task arena with concurrency equal to one. But here comes synchronization problems between graphs, so I suppose that is not what you want. Could you, please, provide a use case for behavior that you need? – Nikita Ponomarev Mar 29 '18 at 16:25
  • Thanks for the reply. Yes, having two graphs does not solve my problem. My use case is simple. I already have a graph where nodes are executables and edges defines before/after dependencies. But, some nodes of my graph are not thread-safe. That is, these non-thread safe nodes needs to be executed on the main thread. I am looking for a way to impose this constraint on the TBB flow graph. – devotee Mar 30 '18 at 14:13
  • I suppose it is better to set **concurrency** of this "not thread-safe nodes" to 1 value. It means, that only one body instance of the node could be executed simultaneously (at any point in time). Read [function_node threshold section] (https://www.threadingbuildingblocks.org/docs/help/reference/flow_graph/func_node_cls.html) and write if you have any questions. – Nikita Ponomarev Apr 05 '18 at 10:43
  • Setting concurrency to 1 isn't a solution to my problem because it only means that the body of that function will run in serial, not necessarily on main thread.. In other words, the flag only implies that multiple executions the function won't happen at the same time. – devotee Apr 05 '18 at 14:44
  • Then, could you please explain what do you mean by this: "these non-thread safe nodes needs to be executed on the main thread". What is so special about main thread? Why you can't use some synchronization primitives (mutexes, lock_guards) inside this node to make it "thread-safe"? – Nikita Ponomarev Apr 06 '18 at 08:51
  • Let's assume that the task is a black box and I don't know the underlying reason. One thing for sure is that it has to run on the main thread. – devotee Apr 06 '18 at 12:26
  • We can come up then with a different situation. Let's create a graph in a separate thread first. Then in the main thread create a while loop that will process concurrent_bounded_queue with some data. This data will be submitted (pushed in the queue) from the nodes that you want to be "thread-safe". But they should be async_node type, in order to pass gateway and return a computed result to the graph. Is this solution, can be relevant to your case? – Nikita Ponomarev Apr 12 '18 at 10:49
  • 1
    Yes, this solution is very much relevant to my case. I have actually applied a similar solution and it worked fine. – devotee May 04 '18 at 14:41

0 Answers0