Boost logo

Boost :

From: Matt Hurd (matt.hurd_at_[hidden])
Date: 2005-08-21 20:59:51


Hi,

Testing my own wrapper on x86_64 bit linux exposed a seeming deadlock
on constructing a read_write_lock with a *::write_locked initial state
in the constructor...

I've distilled it to the plain code below that exhibits the same failure.

Using a read_lock state on the same works without deadlock (or safety
is this case) as expected. Using a scoped_write_lock worked once but
deadlocked mostly.

A normal mutex and recursive mutex works as expected.

I'm using 1.33. Is this a known bug or am I using the read_write
stuff incorrectly?

Regards,

Matt.
matthurd_at_[hidden]

____________________________________

my test in question:...

void synch_test_019()
{
    static int global_count = 0;
    static boost::read_write_mutex doobie(
boost::read_write_scheduling_policy::writer_priority );
    long number_of_threads = 10;
    static long inner_loop = 1000;
    

    ZOMOJO_WORKER_THREAD_BEGIN( inner_loop )
        {
            boost::read_write_mutex::scoped_read_write_lock lk(doobie,
                                     
boost::read_write_lock_state::write_locked);
            global_count = global_count + 1;
        }
    ZOMOJO_WORKER_THREAD_END( number_of_threads )

    BOOST_MESSAGE( "orderly progression = " << inner_loop * number_of_threads );
    BOOST_MESSAGE( "concurrent progression from this run = " << global_count );
    
    BOOST_CHECK_PREDICATE(std::equal_to<int>(), (global_count)(
inner_loop * number_of_threads) );
    
}
_________________________________________________

The helper macros
_________________________________________________

#ifndef ZOMOJO_THREAD_TEST_HELPER_HPP_20050816
#define ZOMOJO_THREAD_TEST_HELPER_HPP_20050816

// A poor man's barrier helper to assist in unit test cases for
parallel execution

#define ZOMOJO_WORKER_THREAD_BEGIN( LoopIterations )
                                      \
        static boost::read_write_mutex m_arbitrary_(
boost::read_write_scheduling_policy::writer_priority ); \
        struct simple_function_arbitrary_
                                   \
        {
                                   \
                static void do_work_arbitrary_()
                                \
                {
                                \
                        boost::read_write_mutex::scoped_read_lock
lk_arbitrary_(m_arbitrary_); \
                        for (int j_arbitrary_ = 0; j_arbitrary_ < (LoopIterations);
j_arbitrary_++) \
                        {

#define ZOMOJO_WORKER_THREAD_END( NumberOfThreads )
                                      \
                        }
                             \
                }
                                \
        };
                                   \
                                                                             
                                   \
        boost::thread_group pool_arbitrary_;
                                   \
                                                                             
                                   \
        {
                                   \
                boost::read_write_mutex::scoped_write_lock lk(m_arbitrary_);
                                \
                for (int i_arbitrary_=0; i_arbitrary_ < NumberOfThreads;
++i_arbitrary_) \
                {
                                \
                        pool_arbitrary_.create_thread(
simple_function_arbitrary_::do_work_arbitrary_ ); \
                }
                                \
        }
                                   \
                                                                             
                                   \
        pool_arbitrary_.join_all();

#endif // ZOMOJO_THREAD_TEST_HELPER_HPP_20050816


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk