« Return to Thread: boost mutex locks

boost mutex locks

by mike_wilson :: Rate this Message:

Reply to Author | View in Thread

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.

 « Return to Thread: boost mutex locks