|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77653 - trunk/libs/context/example
From: oliver.kowalke_at_[hidden]
Date: 2012-03-30 14:54:31
Author: olli
Date: 2012-03-30 14:54:31 EDT (Fri, 30 Mar 2012)
New Revision: 77653
URL: http://svn.boost.org/trac/boost/changeset/77653
Log:
context: refactor unwind example (recursive call)
Text files modified:
trunk/libs/context/example/unwind.cpp | 18 ++++++++----------
1 files changed, 8 insertions(+), 10 deletions(-)
Modified: trunk/libs/context/example/unwind.cpp
==============================================================================
--- trunk/libs/context/example/unwind.cpp (original)
+++ trunk/libs/context/example/unwind.cpp 2012-03-30 14:54:31 EDT (Fri, 30 Mar 2012)
@@ -21,13 +21,15 @@
{ std::cout << "~X()" << std::endl; }
};
-void fn()
+void fn( int n)
{
- X x;
-
- for( int i = 0;; ++i)
+ if ( 0 < n)
+ {
+ X x;
+ fn ( --n);
+ }
+ else
{
- std::cout << "fn(): " << i << std::endl;
ctx.suspend();
}
}
@@ -35,14 +37,10 @@
int main( int argc, char * argv[])
{
ctx = boost::contexts::context(
- fn,
+ fn, 5,
boost::contexts::default_stacksize(),
boost::contexts::no_stack_unwind, boost::contexts::return_to_caller);
ctx.start();
- for ( int i = 0; i < 4; ++i)
- {
- ctx.resume();
- }
std::cout << "ctx is complete: " << std::boolalpha << ctx.is_complete() << "\n";
std::cout << "call ctx.unwind_stack()" << std::endl;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk