Boost logo

Boost Users :

Subject: [Boost-users] [threads] calling unlock twice
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-05-17 11:12:44


Hello *,

I wrote a code which used a RAII idiom to lock multiple mutex instances in
ctor and unlock them in dtor.

This resulted in the class similar to:

struct lock_many
{
    lock_many(mutex& m1, mutex& m2, ...)
       : m1_(m1), ...
    {
       boost::lock(*m1_, *m2_, ...);
    }

    ~lock_many()
    {
        //some asserts here, which ensure that either all mutex pointers are
NULL or unequl to each other
        if(m1_==NULL && m2_==NULL && ...)
           return; // all are NULL no unlock needed

    }

   private:
     mutex* m1_;
     mutex* m2_;
};



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net