Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57729 - sandbox/fiber/libs/fiber/examples
From: oliver.kowalke_at_[hidden]
Date: 2009-11-17 15:06:20


Author: olli
Date: 2009-11-17 15:06:19 EST (Tue, 17 Nov 2009)
New Revision: 57729
URL: http://svn.boost.org/trac/boost/changeset/57729

Log:
- example for at_fiber_exit()

Added:
   sandbox/fiber/libs/fiber/examples/at_exit.cpp (contents, props changed)
Text files modified:
   sandbox/fiber/libs/fiber/examples/Jamfile.v2 | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: sandbox/fiber/libs/fiber/examples/Jamfile.v2
==============================================================================
--- sandbox/fiber/libs/fiber/examples/Jamfile.v2 (original)
+++ sandbox/fiber/libs/fiber/examples/Jamfile.v2 2009-11-17 15:06:19 EST (Tue, 17 Nov 2009)
@@ -23,6 +23,7 @@
         <threading>multi
     ;
 
+exe at_exit : at_exit.cpp ;
 exe suspend : suspend.cpp ;
 exe join : join.cpp ;
 exe interrupt : interrupt.cpp ;

Added: sandbox/fiber/libs/fiber/examples/at_exit.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/examples/at_exit.cpp 2009-11-17 15:06:19 EST (Tue, 17 Nov 2009)
@@ -0,0 +1,48 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+
+#include <boost/bind.hpp>
+#include <boost/system/system_error.hpp>
+
+#include <boost/fiber.hpp>
+
+void at_exit()
+{ std::cout << "at_exit()" << std::endl; }
+
+void fn()
+{
+ boost::this_fiber::at_fiber_exit( at_exit);
+ std::cout << "fn()" << std::endl;
+}
+
+int main()
+{
+ try
+ {
+ boost::fibers::scheduler sched;
+
+ sched.make_fiber( fn);
+
+ std::cout << "start" << std::endl;
+
+ for (;;)
+ {
+ while ( sched.run() );
+ if ( sched.empty() ) break;
+ }
+
+ std::cout << "finish" << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( boost::system::system_error const& e)
+ { std::cerr << "system_error: " << e.code().value() << std::endl; }
+ catch ( boost::fibers::scheduler_error const& e)
+ { std::cerr << "scheduler_error: " << e.what() << std::endl; }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch (...)
+ { std::cerr << "unhandled exception" << std::endl; }
+ return EXIT_FAILURE;
+}


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