2013-07-22 4 views
0

하나의 메시지를 전달하기 전에 2 개의 들어오는 메시지를 축적해야합니다. continue_node의 설명서에는 임계 값 매개 변수 T가 언급되어 있지만 항상 연결된 선행자 수와 동일한 지 여부는 명확하지 않습니다. 제 경우에는 전임자가 하나 밖에 없지만 T = 2를 원합니다. 이것이 가능합니까?스레드 구성 블록 흐름 그래프 - "계산 중"노드 만들기

MessageForwarder이 (사전 정의가없는?) 몸 전달자 간단한 메시지입니다
continue_node<continue_msg> count2(g, 1, MessageForwarder()); 
make_edge(some_message_generator, count2); 
T==2; // hopefully true? 

,

class MessageForwarder { 
    continue_msg operator()(continue_msg /*m*/) { 
     return continue_msg(); 
    } 
}; 

내가 여기에 대한 조언이나 제작의 가능성이 다른 방법을 듣고 기뻐 것 간단한 "계산 노드".

답변

1

추측했듯이 continue_node는 선행 작업의 수와 동일한 수의 continue_msg를 수신 할 때까지 본문을 시작하지 않습니다. 생성자에서 선행 작업 수를 지정하면 해당 수는 해당 수로 초기화되고 노드에 가장자리를 추가하면 해당 수를 증가시킵니다. I 이것을 설명하는 작은 프로그램을 포함하고

는 :

#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 1에 continue_node의 counting_node2를 초기화하고, 에지에 추가. 출력은

Received continue_msg 1 
Received continue_msg 2 
Received continue_msg 3 
Received continue_msg 4 
Received continue_msg 5 

당신은 mutlifunction_nodes이 할 수있는 또 다른 방법을 an answer on the TBB forum site 볼 수 있어야한다.