Boost logo

Boost Users :

Subject: [Boost-users] [thread] unlock
From: gast128 (gast128_at_[hidden])
Date: 2010-10-23 07:56:14


Hello all,

When using unique_lock in combination with mutex, one should only lock /
unlock thru the unique_lock, otherwise its managment gets corrupted. However
the unlock fct. is also offered in the mutex, which makes it vunerable for
small typo errors like (code simplified):

void foo()
{
   boost::mutex mtx;

   for (size_t n = 0; n != 2; ++n)
   {
      boost::unique_lock<boost::mutex> lck(mtx);

      //mtx.unlock(); //hang in next lock attempt
      lck.unlock(); //ok
   }
}

Not sure if something can be done about this; mail only meant to share
information.


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