From: Matt Hurd (matt.hurd_at_[hidden])
Date: 2005-08-30 18:44:59
>On 31/08/05, John Maddock <john_at_[hidden]> wrote:
> Matt, can you distil this test case a little more please:
> * Get rid of the macros so we can read the code :-)
> * Don't use Boost.Test for the tests, it's *not* thread safe, and bad things
> may be happening in there.
> * Don't declare variables as function-static: it's not thread safe. I'm not
> sure if this is an issue or not from reading the code, with those macros in
> place it's hard to see which bits are getting called by multiple threads.
Hopefully this is a little more readable. My set up is gcc 3.3.5 on
Suse 9.3 pro x86_64 with dual opterons.
Hope this helps,
using namespace boost;
// these definitions deadlock
read_write_mutex guard( read_write_scheduling_policy::writer_priority );
typedef read_write_mutex::scoped_write_lock test_lock_type;
// these definitions work as expected
// mutex guard;
// typedef mutex::scoped_lock test_lock_type;
long global_count = 0;
long loop_count_for_test = 100000;
for (long i=0; i< loop_count_for_test; ++i )
test_lock_type lk( guard );
int number_of_threads = 100;
for (int i=0; i < number_of_threads; ++i)
pool.create_thread( do_work );
std::cout << "We should get here without a deadlock\n";
std::cout << "global count = " << global_count << "\n";
std::cout << "global count should be = "
<< loop_count_for_test * number_of_threads
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk