From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/fiber/examples/range_for.cpp | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/boost/libs/fiber/examples/range_for.cpp (limited to 'src/boost/libs/fiber/examples/range_for.cpp') diff --git a/src/boost/libs/fiber/examples/range_for.cpp b/src/boost/libs/fiber/examples/range_for.cpp new file mode 100644 index 00000000..8a1dbba1 --- /dev/null +++ b/src/boost/libs/fiber/examples/range_for.cpp @@ -0,0 +1,53 @@ + +// Copyright Oliver Kowalke 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include + +typedef boost::fibers::unbuffered_channel< unsigned int > channel_t; + +void foo( channel_t & chan) { + chan.push( 1); + chan.push( 1); + chan.push( 2); + chan.push( 3); + chan.push( 5); + chan.push( 8); + chan.push( 12); + chan.close(); +} + +void bar( channel_t & chan) { + for ( unsigned int value : chan) { + std::cout << value << " "; + } + std::cout << std::endl; +} + +int main() { + try { + channel_t chan; + + boost::fibers::fiber f1( & foo, std::ref( chan) ); + boost::fibers::fiber f2( & bar, std::ref( chan) ); + + f1.join(); + f2.join(); + + std::cout << "done." << std::endl; + + return EXIT_SUCCESS; + } catch ( std::exception const& e) { + std::cerr << "exception: " << e.what() << std::endl; + } catch (...) { + std::cerr << "unhandled exception" << std::endl; + } + return EXIT_FAILURE; +} -- cgit v1.2.3