Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81505 - trunk/libs/thread/example
From: vicente.botet_at_[hidden]
Date: 2012-11-24 03:08:11


Author: viboes
Date: 2012-11-24 03:08:10 EST (Sat, 24 Nov 2012)
New Revision: 81505
URL: http://svn.boost.org/trac/boost/changeset/81505

Log:
Thread: add traces to future_then
Text files modified:
   trunk/libs/thread/example/future_then.cpp | 47 ++++++++++++++++++++++++++++++++++-----
   1 files changed, 41 insertions(+), 6 deletions(-)

Modified: trunk/libs/thread/example/future_then.cpp
==============================================================================
--- trunk/libs/thread/example/future_then.cpp (original)
+++ trunk/libs/thread/example/future_then.cpp 2012-11-24 03:08:10 EST (Sat, 24 Nov 2012)
@@ -3,29 +3,64 @@
 // 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)
 
-#define BOOST_THREAD_VERSION 4
+//#define BOOST_THREAD_VERSION 4
+#define BOOST_THREAD_USES_LOG
 #define BOOST_THREAD_DONT_PROVIDE_FUTURE_INVALID_AFTER_GET
 
+#include <boost/thread/detail/log.hpp>
 #include <boost/thread/future.hpp>
-#include <iostream>
+#include <boost/assert.hpp>
 #include <string>
 #if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
 
 int p1()
 {
+ BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
   return 123;
 }
 
 int p2(boost::future<int>& f)
 {
- return 2 * f.get();
+ BOOST_THREAD_LOG << "<P2" << BOOST_THREAD_END_LOG;
+ try
+ {
+ return 2 * f.get();
+ }
+ catch (std::exception& ex)
+ {
+ BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
+ BOOST_ASSERT(false);
+ }
+ catch (...)
+ {
+ BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
+ BOOST_ASSERT(false);
+ }
+ BOOST_THREAD_LOG << "P2>" << BOOST_THREAD_END_LOG;
 }
 
 int main()
 {
- boost::future<int> f1 = boost::async(p1);
- boost::future<int> f2 = f1.then(p2);
- std::cout << f2.get() << std::endl;
+ BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
+ try
+ {
+ boost::future<int> f1 = boost::async(&p1);
+ BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
+ boost::future<int> f2 = f1.then(&p2);
+ BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
+ BOOST_THREAD_LOG << f2.get() << BOOST_THREAD_END_LOG;
+ }
+ catch (std::exception& ex)
+ {
+ BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
+ return 1;
+ }
+ catch (...)
+ {
+ BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
+ return 2;
+ }
+ BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
   return 0;
 }
 #else


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