As you surmised, the continue_node doesn't fire the body until it receives a number of continue_msgs equivalent to the number of predecessors. If you specify a predecessor count in the constructor, the count is initialized to that number, and adding an edge to the node increments that count.
I am including a small program demonstrating this:
#include "tbb/flow_graph.h"
#include <iostream>
using namespace tbb::flow;
struct continue_body {
continue_msg operator()(const continue_msg& /*c*/) {
return continue_msg();
}
};
struct output_body {
int my_count;
output_body() { my_count = 0; }
continue_msg operator()(const continue_msg&) {
std::cout << "Received continue_msg " << ++my_count << "\n";
}
};
int
main() {
graph g;
continue_node<continue_msg> counting_node(g, continue_body());
continue_node<continue_msg> counting_node2(g, 1, continue_body());
function_node<continue_msg> output_node(g, serial, output_body());
make_edge(counting_node, counting_node2);
make_edge(counting_node2, output_node);
for(int i = 0; i < 10; ++i) {
counting_node.try_put(continue_msg());
}
g.wait_for_all();
}
I initialized the continue_node counting_node2 to 1, and added an edge to it. The output should be
Received continue_msg 1
Received continue_msg 2
Received continue_msg 3
Received continue_msg 4
Received continue_msg 5
You can look at an answer on the TBB forum site for another way to do this with mutlifunction_nodes.