2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-23 05:22:16 +00:00
Files
context/example/fiber/hosting_thread.cpp
Oliver Kowalke 543e87e53f P0876R3
2018-07-02 09:10:44 +02:00

32 lines
1.1 KiB
C++

// Copyright Oliver Kowalke 2016.
// 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)
#define UNW_LOCAL_ONLY
#include <cstdlib>
#include <iostream>
#include <thread>
#include <boost/context/fiber.hpp>
namespace ctx = boost::context;
int main() {
ctx::fiber_handle f{
[](ctx::fiber_handle && m){
std::cout << "m in main thread: " << std::boolalpha << m.can_resume() << std::endl;
ctx::fiber_handle * pm = & m;
std::thread{ [pm]{ std::cout << "m in other thread: " << std::boolalpha << pm->can_resume() << std::endl; }}.join();
m = std::move( m).resume();
return std::move( m);
}};
std::cout << "f: before resumption: " << std::boolalpha << f.can_resume() << std::endl;
f = std::move( f).resume();
std::cout << "f: after resumption: " << std::boolalpha << f.can_resume() << std::endl;
std::cout << "main: done" << std::endl;
return EXIT_SUCCESS;
}