7 #include <boost/thread/mutex.hpp>
8 #include <boost/thread/thread.hpp>
10 #define BOOST_AUTO_TEST_MAIN
11 #include <boost/test/auto_unit_test.hpp>
13 using namespace boost::unit_test;
15 boost::mutex io_mutex;
20 Worker(yp2::Session *session, int nr = 0)
21 : m_session(session), m_nr(nr){};
23 void operator() (void) {
24 for (int i=0; i < 100; ++i)
26 m_id = m_session->id();
33 boost::mutex::scoped_lock scoped_lock(io_mutex);
34 std::cout << "Worker " << m_nr
35 << " session.id() " << m_id << std::endl;
39 yp2::Session *m_session;
46 BOOST_AUTO_TEST_CASE( testsession2 )
53 const int num_threads = 10;
54 boost::thread_group thrds;
56 for (int i=0; i < num_threads; ++i)
58 Worker w(&session, i);
59 thrds.add_thread(new boost::thread(w));
63 BOOST_CHECK (session.id() == 1001);
66 catch (std::exception &e) {
67 std::cout << e.what() << "\n";
78 * indent-tabs-mode: nil
80 * vim: shiftwidth=4 tabstop=8 expandtab