#include #include #include class Foo { public: Foo() : _lock(_mutex, boost::defer_lock), _thread1(boost::bind(&Foo::multi, this)), _thread2(boost::bind(&Foo::multi, this)) {} private: void multi() { _lock.lock(); } boost::mutex _mutex; boost::mutex::scoped_lock _lock; boost::thread _thread1; boost::thread _thread2; }; int main() { Foo foo; while(true) { usleep(100000); } return 0; }