Click to See Complete Forum and Search --> : Boost Mutex locking


Razor92
November 25th, 2008, 10:00 AM
Could some one please give me an example of how to explitly lock and unlock mutexs using the boost libarys because i cant seem to make it work.

Thanks

Codeplug
November 25th, 2008, 10:43 AM
What did you try and what was the error?

gg

zerver
November 25th, 2008, 10:46 AM
It depends on your Boost version, but you could try something like this.
If you are using older Boost versions that don't have the lock/unlock functions there are some hacks that may help.

boost::mutex mymutex;

void myprotectecfunction() {
boost::mutex::scoped_lock mylock(mymutex, boost::defer_lock); // defer_lock makes it initially unlocked
mylock.lock();
mylock.unlock();
}