last changes from bloomberg.
This commit is contained in:
70
cpp/tbb/simple_flow_graph.cpp
Normal file
70
cpp/tbb/simple_flow_graph.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
VIM: let b:lcppflags="-std=c++11 -O2 -pthread"
|
||||
VIM: let b:wcppflags="/O2 /EHsc /DWIN32"
|
||||
VIM: let b:cppflags=g:Iboost.g:Itbb
|
||||
VIM: let b:ldflags=g:Lboost.g:Ltbb
|
||||
VIM: let b:ldlibpath=g:Bboost.g:Btbb
|
||||
VIM: let b:argv=""
|
||||
*/
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
using namespace tbb::flow;
|
||||
|
||||
typedef std::shared_ptr<std::string> msg_type;
|
||||
|
||||
struct body {
|
||||
std::string my_name;
|
||||
body( const char *name ) : my_name(name) {}
|
||||
void operator()( msg_type msg ) const {
|
||||
std::stringstream ss;
|
||||
ss << my_name << " got " << *msg << std::endl;
|
||||
std::cout << ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{try{
|
||||
graph g;
|
||||
|
||||
broadcast_node<msg_type> start( g );
|
||||
continue_node<msg_type> a( g, body("A"));
|
||||
continue_node<msg_type> b( g, body("B"));
|
||||
continue_node<msg_type> c( g, body("C"));
|
||||
continue_node<msg_type> d( g, body("D"));
|
||||
continue_node<msg_type> e( g, body("E"));
|
||||
|
||||
make_edge( start, a );
|
||||
make_edge( start, b );
|
||||
make_edge( a, c );
|
||||
make_edge( b, c );
|
||||
make_edge( c, d );
|
||||
make_edge( a, e );
|
||||
|
||||
for (int i = 0; i < 3; ++i ) {
|
||||
std::stringstream ss;
|
||||
ss << i << std::endl;
|
||||
|
||||
start.try_put( std::make_shared( ss.str() ) );
|
||||
g.wait_for_all();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch ( const std::exception& e )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "unknown exception." << std::endl;
|
||||
return 1;
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user