2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-01-30 07:52:07 +00:00
Files
fiber/examples/simple.cpp
Oliver Kowalke 9ad0ec1937 adapt examples
2013-01-30 19:16:19 +01:00

42 lines
785 B
C++

#include <cstdlib>
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/fiber/all.hpp>
inline
void fn( std::string const& str, int n)
{
for ( int i = 0; i < n; ++i)
{
std::cout << i << ": " << str << std::endl;
boost::this_fiber::yield();
}
}
int main()
{
boost::fibers::round_robin ds;
boost::fibers::scheduling_algorithm( & ds);
try
{
boost::fibers::fiber f1( boost::bind( fn, "abc", 5) );
boost::fibers::fiber f2( boost::bind( fn, "xyz", 7) );
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;
}