I'm new to the boost threads library. I have a situation where I acquire a scoped_lock in one function and need to wait on it in a callee.
The code is on the lines of:
class HavingMutex
{
public:
...
private:
static boost::mutex m;
static boost::condition_variable *c;
static void a();
static void b();
static void d();
}
void HavingMutex::a()
{
boost::mutex::scoped_lock lock(m);
...
b() //Need to pass lock here. Dunno how !
}
void HavingMutex::b(lock)
{
if (some condition)
d(lock) // Need to pass lock here. How ?
}
void HavingMutex::d(//Need to get lock here)
{
c->wait(lock); //Need to pass lock here (doesn't allow direct passing of mutex m)
}
Basically, in function d(), I need to access the scoped lock I acquired in a() so that I can wait on it. (Some other thread will notify).
Any help appreiciated. Thanks !
static. Is that really what you want? Thismutexis a property of the class itself? I suppose it's not unheard of, but in my experience makes for a more challenging metaphor. Could you/should you just use themutexto protect some of the instance members instead? - Brian CainHavingMutexclass is supposed to do? - Brian Cainboost, it's almost always because ifboostlet me do that it would blow up in my face. So, rather than answer "how can I pass a reference ofscoped_lock?" I'd prefer to ask another question:b()may modify some class members and then signal a thread or thread(s) currentlywait()ing in thec()method? - Brian Cain