1 // Copyright (C) 2013 Vicente Botet 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #include <boost/config.hpp> 7 8 #define BOOST_THREAD_VERSION 5 9 //#define BOOST_THREAD_USES_LOG 10 #define BOOST_THREAD_USES_LOG_THREAD_ID 11 #if ! defined BOOST_NO_CXX11_DECLTYPE 12 #define BOOST_RESULT_OF_USE_DECLTYPE 13 #endif 14 #include <boost/thread/detail/log.hpp> 15 #include <boost/thread/executors/loop_executor.hpp> 16 #include <boost/assert.hpp> 17 #include <boost/thread/thread_only.hpp> 18 #include <string> 19 20 #ifdef BOOST_MSVC 21 #pragma warning(disable: 4127) // conditional expression is constant 22 #endif 23 p1()24void p1() 25 { 26 BOOST_THREAD_LOG 27 << boost::this_thread::get_id() << " P1" << BOOST_THREAD_END_LOG; 28 } 29 p2()30void p2() 31 { 32 BOOST_THREAD_LOG 33 << boost::this_thread::get_id() << " P2" << BOOST_THREAD_END_LOG; 34 } 35 submit_some(boost::loop_executor & tp)36void submit_some(boost::loop_executor& tp) { 37 tp.submit(&p1); 38 tp.submit(&p2); 39 tp.submit(&p1); 40 tp.submit(&p2); 41 tp.submit(&p1); 42 tp.submit(&p2); 43 tp.submit(&p1); 44 tp.submit(&p2); 45 tp.submit(&p1); 46 tp.submit(&p2); 47 } 48 main()49int main() 50 { 51 BOOST_THREAD_LOG 52 << boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG; 53 { 54 try 55 { 56 boost::loop_executor tp; 57 submit_some(tp); 58 tp.run_queued_closures(); 59 submit_some(tp); 60 tp.run_queued_closures(); 61 } 62 catch (std::exception& ex) 63 { 64 BOOST_THREAD_LOG 65 << "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG; 66 return 1; 67 } 68 catch (...) 69 { 70 BOOST_THREAD_LOG 71 << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG; 72 return 2; 73 } 74 } 75 76 BOOST_THREAD_LOG 77 << boost::this_thread::get_id() << "MAIN>" << BOOST_THREAD_END_LOG; 78 return 0; 79 } 80