是否有可能有类似 limiter_node<T>
的东西?它可以防止队列溢出,但不是丢弃不适合队列的消息,而是将它们转发到其他节点?我想要类似的东西
typedef std::string S;
using namespace tbb::flow;
source_node<S> input(g, Input(), false);
limiter_node<S> limiter(g, queue_len);
function_node<S, S> processor(g, threadpool_size, Processor());
function_node<S, int> output(g, serial, Output());
make_edge(input, limiter);
make_edge(limiter, processor);
make_edge(limiter.magic_forwarder_of_failed_deliveries_thank_you, output); // ???
make_edge(processor, output);
make_edge(output, limiter.decrement);
基本上,我想用大量阻塞 IO 绑定(bind)的“节点”处理尽可能多的数据,并将其余数据直接转发到未处理的输出节点。
最佳答案
(披露:我在英特尔从事英特尔线程构建模块的工作。)
我同意 yohjp 的观点,你可以用 multifunction_node 来做到这一点。
typedef multifunction_node< S, tuple< S, S > > mnode_t;
struct Forwarder {
// This assumes
// port 0 is connected to the limiter
// port 1 is the alternative path
void operator()( const S &s, mnode_t::output_ports_type &outs ) {
if ( !get<0>(outs).try_put(s) ) {
get<1>(outs).try_put(s);
}
} };
随着边缘的改变,使得:
make_edge(input, forwarder);
make_edge(output_port<0>(forwarder), limiter);
make_edge(limiter, processor);
make_edge(output_port<1>(forwarder), output);
您还必须想出一种方法,使减量只对那些通过处理器的事情进行调用。
关于c++ - Thread Building Blocks 流程图 — 类似 limiter_node 的东西,不会丢弃消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16854354/