|
Boost Users : |
From: Peter G (yg-boost-users_at_[hidden])
Date: 2003-05-11 02:42:10
hi there...
what is the scope of locked variables? assuming that i declare a mutex in
say a class scope.. and then lock it in some inner scope - say in a
function.. what variables get locked? is it all the variables which are in
the scope of the declaration (ie all the variables which are declared in the
class)? or is it only the ones which are being used in that particular
function (so that perhaps another thread could use the rest at "the same
time")?
for example:
class Class1
{
public:
Class1::Class1();
~Class1::Class1();
void f(int new)
{
boost::mutex::scoped_lock scoped_lock(mutex_outer) ;
var1 = new;
}
void g(int new)
{
boos::mutex mutex_inner;
boost::mutex::scoped_lock scoped_lock(mutex_inner) ;
var1 = new;
}
private:
boost::mutex mutex_outer;
Class2 some_member_object;
int var1;
int var2;
};
what gets locked when f() is called?
when should i use g()?
how do I go about just locking say var1 but NOT var2?
if i lock the mutex in this class scope, does that mean that all the
variables in some_member_object are locked as well?
also, should i set up locks anytime i am using an object which might be
accesses by another thread (even if I am just reading it) or is it enough to
only lock variables when i am changing them?
i know that's a lot of questions, but any help would be greatly appreciated.
cheers
peter
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