From 0735822d19a30ea363618dc5814c212ce74f2080 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Thu, 5 Mar 2015 17:26:05 +0100 Subject: [PATCH 1/3] update documentation --- doc/execution_context.qbk | 46 ++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/doc/execution_context.qbk b/doc/execution_context.qbk index 8e5f3ec..b09fc40 100644 --- a/doc/execution_context.qbk +++ b/doc/execution_context.qbk @@ -121,32 +121,48 @@ of the stack.] If the function executed inside a __econtext__ emitts ans exception, `std::terminate()` 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; + } + [heading Class `execution_context`] From b2af03e76b3a1058d13091f4a6e716ce5af2a135 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Thu, 5 Mar 2015 17:26:19 +0100 Subject: [PATCH 2/3] update examples --- example/execution_context/Jamfile.v2 | 8 ++++ example/execution_context/fibonacci.cpp | 36 ++++++++++++++++ example/execution_context/parameter.cpp | 55 +++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 example/execution_context/fibonacci.cpp create mode 100644 example/execution_context/parameter.cpp 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< Date: Thu, 5 Mar 2015 17:28:50 +0100 Subject: [PATCH 3/3] update docu --- doc/context.xml | 48 ++++++++++++++++++++++------------ doc/execution_context.qbk | 3 +++ doc/html/context/econtext.html | 46 +++++++++++++++++++++----------- doc/html/index.html | 2 +- 4 files changed, 67 insertions(+), 32 deletions(-) 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; +} 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