Boost logo

Boost Users :

Subject: [Boost-users] boost mutex locks
From: mike_wilson (me95mlp_at_[hidden])
Date: 2009-07-15 07:53:09


Hi,

I am a newbie to C++ multi threading (did a bit in java) and would like for
information on the following...

consider:-

class MyClass
{
   void SetMyObject(SomeClass const& value)
   {
      boost::mutex::scoped_lock lock(objectMutex);
      myObject = value;
   }
   SomeClass SetMyObject() const
   {
      boost::mutex::scoped_lock lock(objectMutex);
      return myObject;
   }
private:
   SomeClass myObject;
   boost::mutex objectMutex;
};

Say one thread accesses the SetMyObject() , given that there is a lock in
the function, it will also lock the GetMyObject() blocking any other
thread from calling?

This kind of implies that wherever in the object there is a lock, any
function owned by the object will be locked to any other thread trying to
access. Is this correct?

Thanks again for your help.

-- 
View this message in context: http://www.nabble.com/boost-mutex-locks-tp24406812p24406812.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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