2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-22 17:12:17 +00:00
Files
context/example/execution_context/cycle.cpp
2015-09-26 20:20:58 +02:00

43 lines
1.2 KiB
C++

// Copyright Oliver Kowalke 2014.
// 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/context/all.hpp>
namespace ctx=boost::context;
ctx::execution_context * other = nullptr;
int main() {
ctx::execution_context ctx1(
[] () mutable {
std::cout << "ctx1 started" << std::endl;
( * other)();
std::cout << "ctx1 will terminate" << std::endl;
});
ctx::execution_context ctx2(
[&ctx1] () mutable {
std::cout << "ctx2 started" << std::endl;
ctx1();
std::cout << "ctx2 will terminate" << std::endl;
});
ctx::execution_context ctx3(
[&ctx1, &ctx2] () mutable {
std::cout << "ctx3 started" << std::endl;
ctx2();
ctx1();
std::cout << "ctx3 will terminate" << std::endl;
});
other = & ctx3;
ctx3();
std::cout << "main: done" << std::endl;
return EXIT_SUCCESS;
}