mirror of
https://github.com/boostorg/coroutine.git
synced 2026-02-19 02:12:22 +00:00
coroutine: initial commit
[SVN r81769]
This commit is contained in:
46
example/echo.cpp
Normal file
46
example/echo.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
// Copyright Oliver Kowalke 2009.
|
||||
// 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 <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/coroutine/all.hpp>
|
||||
|
||||
typedef boost::coroutines::coroutine< void() > coro_t;
|
||||
|
||||
void echo( coro_t & ca, int i)
|
||||
{
|
||||
std::cout << i;
|
||||
ca();
|
||||
}
|
||||
|
||||
void runit( coro_t & ca)
|
||||
{
|
||||
std::cout << "started! ";
|
||||
for ( int i = 0; i < 10; ++i)
|
||||
{
|
||||
coro_t c( boost::bind( echo, _1, i) );
|
||||
while ( c)
|
||||
c();
|
||||
ca();
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char * argv[])
|
||||
{
|
||||
{
|
||||
coro_t c( runit);
|
||||
while ( c) {
|
||||
std::cout << "-";
|
||||
c();
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\nDone" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user