]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/test_5502.cpp
1 // Copyright (C) 2010 Vicente Botet
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)
8 // g++ test.cpp -lboost_thread-mt && ./a.out
10 // the ration of XXX and YYY determines
11 // if this works or deadlocks
15 #include <boost/thread/thread_only.hpp>
16 #include <boost/thread/shared_mutex.hpp>
20 #include <boost/detail/lightweight_test.hpp>
24 //void sleepmillis(useconds_t miliis)
25 void sleepmillis(int miliis
)
27 //usleep(miliis * 1000);
28 boost::this_thread::sleep(boost::posix_time::milliseconds(miliis
));
31 void worker1(boost::shared_mutex
* lk
, int * x
)
34 cout
<< "lock b try " << *x
<< endl
;
37 if (lk
->timed_lock(boost::posix_time::milliseconds(XXX
))) break;
40 cout
<< "lock b got " << *x
<< endl
;
45 void worker2(boost::shared_mutex
* lk
, int * x
)
47 cout
<< "lock c try" << endl
;
50 cout
<< "lock c got" << endl
;
52 cout
<< "lock c unlocked" << endl
;
60 boost::shared_mutex
* lk
= new boost::shared_mutex();
63 cout
<< "lock a" << endl
;
67 boost::thread
t1(boost::bind(worker1
, lk
, &x1
));
75 boost::thread
t2(boost::bind(worker2
, lk
, &x2
));
80 cout
<< "unlock a" << endl
;
82 for (int i
= 0; i
< 2000; i
++)