diff --git a/doc/context.xml b/doc/context.xml
index 868bb6a..f77e217 100644
--- a/doc/context.xml
+++ b/doc/context.xml
@@ -1,6 +1,6 @@
-
@@ -612,31 +612,47 @@
role="identifier">exception_ptr can used to store exceptions
thrown inside the other context.
-class my_context {
+class X {
private:
- std::exception_ptr excptr_;
- execution_context ctx_;
+ int * inp_;
+ std::string outp_;
+ std::exception_ptr excptr_;
+ boost::context::execution_context caller_;
+ boost::context::execution_context callee_;
public:
- my_context() :
+ X() :
+ inp_( nullptr),
+ outp_(),
excptr_(),
- ctx_( fixedsize_stack(),
- [&excptr_](){
- try {
- ...
- } catch (...) {
- excptr_ = std::current_exception();
- }
- }) {
- }
+ caller_( boost::context::execution_context::current() ),
+ callee_( boost::context::fixedsize_stack(),
+ [=] () {
+ try {
+ int i = * inp_;
+ outp_ = boost::lexical_cast< std::string >( i);
+ caller_.resume();
+ } catch (...) {
+ excptr_ = std::current_exception();
+ }
+ })
+ {}
- void run() {
- ctx_.resume();
+ std::string operator()( int i) {
+ inp_ = & i;
+ callee_.resume();
if ( excptr_) {
std::rethrow_exception( excptr_);
}
+ return outp_;
}
};
+
+int main() {
+ X x;
+ std::cout << x( 7) << std::endl;
+ std::cout << "done" << std::endl;
+}
( i);
+ caller_.resume();
+ } catch (...) {
+ excptr_ = std::current_exception();
+ }
+ })
+ {}
- void run() {
- ctx_.resume();
+ std::string operator()( int i) {
+ inp_ = & i;
+ callee_.resume();
if ( excptr_) {
std::rethrow_exception( excptr_);
}
+ return outp_;
}
};
+ int main() {
+ X x;
+ std::cout << x( 7) << std::endl;
+ std::cout << "done" << std::endl;
+ }
+
[heading Class `execution_context`]
diff --git a/doc/html/context/econtext.html b/doc/html/context/econtext.html
index f3f61ea..fa9d680 100644
--- a/doc/html/context/econtext.html
+++ b/doc/html/context/econtext.html
@@ -180,31 +180,47 @@
is called - std::exception_ptr can used to store exceptions
thrown inside the other context.
-class my_context {
+class X {
private:
- std::exception_ptr excptr_;
- execution_context ctx_;
+ int * inp_;
+ std::string outp_;
+ std::exception_ptr excptr_;
+ boost::context::execution_context caller_;
+ boost::context::execution_context callee_;
public:
- my_context() :
+ X() :
+ inp_( nullptr),
+ outp_(),
excptr_(),
- ctx_( fixedsize_stack(),
- [&excptr_](){
- try {
- ...
- } catch (...) {
- excptr_ = std::current_exception();
- }
- }) {
- }
+ caller_( boost::context::execution_context::current() ),
+ callee_( boost::context::fixedsize_stack(),
+ [=] () {
+ try {
+ int i = * inp_;
+ outp_ = boost::lexical_cast< std::string >( i);
+ caller_.resume();
+ } catch (...) {
+ excptr_ = std::current_exception();
+ }
+ })
+ {}
- void run() {
- ctx_.resume();
+ std::string operator()( int i) {
+ inp_ = & i;
+ callee_.resume();
if ( excptr_) {
std::rethrow_exception( excptr_);
}
+ return outp_;
}
};
+
+int main() {
+ X x;
+ std::cout << x( 7) << std::endl;
+ std::cout << "done" << std::endl;
+}
diff --git a/doc/html/index.html b/doc/html/index.html
index 5c412bd..933a9ec 100644
--- a/doc/html/index.html
+++ b/doc/html/index.html
@@ -63,7 +63,7 @@
-Last revised: February 18, 2015 at 17:39:58 GMT |
+Last revised: March 05, 2015 at 16:26:35 GMT |
|
diff --git a/example/execution_context/Jamfile.v2 b/example/execution_context/Jamfile.v2
index 5810d6f..1b9a610 100644
--- a/example/execution_context/Jamfile.v2
+++ b/example/execution_context/Jamfile.v2
@@ -37,3 +37,11 @@ exe segmented
exe parser
: parser.cpp
;
+
+exe fibonacci
+ : fibonacci.cpp
+ ;
+
+exe parameter
+ : parameter.cpp
+ ;
diff --git a/example/execution_context/fibonacci.cpp b/example/execution_context/fibonacci.cpp
new file mode 100644
index 0000000..7424fef
--- /dev/null
+++ b/example/execution_context/fibonacci.cpp
@@ -0,0 +1,36 @@
+
+// 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
+#include
+
+#include
+
+#define yield(x) p=x; mctx.resume();
+
+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.resume();
+ std::cout<
+#include
+#include
+#include
+
+#include
+#include
+
+class X{
+private:
+ int * inp_;
+ std::string outp_;
+ std::exception_ptr excptr_;
+ boost::context::execution_context caller_;
+ boost::context::execution_context callee_;
+
+public:
+ X():
+ inp_( nullptr),
+ outp_(),
+ excptr_(),
+ caller_(boost::context::execution_context::current()),
+ callee_(boost::context::fixedsize_stack(),
+ [=](){
+ try {
+ int i = * inp_;
+ outp_ = boost::lexical_cast(i);
+ caller_.resume();
+ } catch (...) {
+ excptr_=std::current_exception();
+ }
+ })
+ {}
+
+ std::string operator()(int i){
+ inp_ = & i;
+ callee_.resume();
+ if(excptr_){
+ std::rethrow_exception(excptr_);
+ }
+ return outp_;
+ }
+};
+
+int main() {
+ X x;
+ std::cout<