2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-23 17:32:16 +00:00
Files
context/example/execution_context/fibonacci.cpp
Oliver Kowalke aadb5968f4 remove parent-tracking in execution_context
- tracking parent inside of execution_context:
- costs performance
- execution_context doesn't realy know which execution_context should be
  executed next (if it's terminating)
- fibers do not care of the parent context -> scheduler decides which is
  the next context
2015-06-03 09:00:21 +02:00

38 lines
910 B
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>
#define yield(x) p=x; mctx();
int main() {
int n=35;
int p=0;
boost::context::execution_context mctx( boost::context::execution_context::current() );
boost::context::execution_context ctx(
boost::context::fixedsize_stack(),
[n,&p,mctx]()mutable{
int a=0;
int b=1;
while(n-->0){
yield(a);
auto next=a+b;
a=b;
b=next;
}
});
for(int i=0;i<10;++i){
ctx();
std::cout<<p<<" ";
}
std::cout<<std::endl;
std::cout << "main: done" << std::endl;
}