From 1ef2dd7467e3a2b3f501a63b870f3b0e627d1389 Mon Sep 17 00:00:00 2001 From: Josh Bradshaw <36052869+joshbradshaw11@users.noreply.github.com> Date: Wed, 15 May 2024 13:00:31 -0400 Subject: [PATCH] Update create_token_based_system.rst I fixed a few logic errors in the example, and lightly tidied it. --- .../tbb_userguide/create_token_based_system.rst | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/doc/main/tbb_userguide/create_token_based_system.rst b/doc/main/tbb_userguide/create_token_based_system.rst index 6d9d642556..7952affec8 100644 --- a/doc/main/tbb_userguide/create_token_based_system.rst +++ b/doc/main/tbb_userguide/create_token_based_system.rst @@ -59,14 +59,12 @@ pull from the ``buffer_node``. graph g; - int src_count = 0; - int number_of_objects = 0; + int number_of_objects = 100; int max_objects = 3; - input_node< big_object * > s( g, [&]( oneapi::tbb::flow_control& fc ) -> big_object* { - if ( src_count < M ) { + if ( src_count < number_of_objects ) { big_object* v = new big_object(); ++src_count; return v; @@ -77,11 +75,8 @@ pull from the ``buffer_node``. } ); s.activate(); - join_node< tuple_t, reserving > j(g); - - buffer_node< token_t > b(g); - + join_node< tuple_t, reserving > j(g); function_node< tuple_t, token_t > f( g, unlimited, []( const tuple_t &t ) -> token_t { @@ -95,14 +90,15 @@ pull from the ``buffer_node``. make_edge( s, input_port<0>(j) ); make_edge( b, input_port<1>(j) ); make_edge( j, f ); - make_edge( f, b ); + // The function node reinserts the token_t back into buffer upon + // completion, completing the cycle. + make_edge( f, b ); b.try_put( 1 ); b.try_put( 2 ); b.try_put( 3 ); - g.wait_for_all();