3 #include <boost/thread.hpp>
4 #include <boost/thread/thread_time.hpp>
9 inline std::ostream & operator<<( std::ostream & str, const thread_data_base & obj )
10 { return str << &obj; }
14 #include "zypp/ByteCount.h"
15 #include "zypp/Pathname.h"
16 #include "zypp/base/Logger.h"
17 #include "zypp/base/LogControl.h"
23 #define MIL MilSync( L_BASEFILE, __FUNCTION__, __LINE__ )._str
28 #warning NOT_REENTRANT
31 template <class Derived>
32 struct ClassLevelLockable
34 typedef boost::recursive_mutex Lockable;
36 typedef boost::lock_guard<Lockable> Lock;
39 Lock( const Derived & obj )
47 template <class Derived>
48 struct ObjectLevelLockable
50 typedef boost::recursive_mutex Lockable;
51 typedef boost::lock_guard<Lockable> Lock;
58 MilSync( const char * file_r, const char * func_r, const int line_r )
60 , _str( zypp::base::logger::getStream( ZYPP_BASE_LOGGER_LOGGROUP, zypp::base::logger::E_MIL, file_r, func_r, line_r ) )
62 typedef boost::recursive_mutex Lockable;
63 static Lockable _mutex;
64 boost::lock_guard<Lockable> _guard;
67 MilSync::Lockable MilSync::_mutex;
73 MIL << "+TE" << boost::this_thread::get_id() << endl;
74 boost::this_thread::sleep( boost::posix_time::seconds(1) );
79 MIL << "-TE" << boost::this_thread::get_id() << endl;
85 MIL << "---" << boost::this_thread::get_id() << endl;
90 MIL << "+++" << boost::this_thread::get_id() << " " << boost::this_thread::interruption_enabled() << endl;
91 boost::this_thread::at_thread_exit( t_exit );
94 boost::this_thread::sleep( boost::posix_time::seconds(1) );
97 int main( int argc, char * argv[] )
99 //zypp::base::LogControl::instance().logfile( "log.restrict" );
100 INT << "===[START]==========================================" << endl;
102 MIL << "M+++" << boost::this_thread::get_id() << endl;
103 boost::thread_group mthreads;
105 mthreads.create_thread( t_main );
106 mthreads.create_thread( t_main );
107 mthreads.create_thread( t_main );
108 mthreads.create_thread( t_main );
109 mthreads.create_thread( t_main );
111 MIL << "M???" << boost::this_thread::get_id() << endl;
112 //boost::this_thread::sleep( boost::posix_time::seconds(10) );
113 mthreads.interrupt_all();
115 MIL << "M---" << boost::this_thread::get_id() << endl;
117 ///////////////////////////////////////////////////////////////////
118 INT << "===[END]============================================" << endl << endl;
119 zypp::base::LogControl::instance().logNothing();