Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::lock does not compile in boost 1.53

Tags:

c++

locking

boost

I am compiling a project. It has the following lines :

boost::mutex::scoped_lock ml(m_meta_mut, boost::defer_lock);
    boost::mutex::scoped_lock tl(m_tables_mut, boost::defer_lock);
    boost::lock(ml, tl);

I am getting lock is not a member of boost on the third line. I am using boost1.53 (the project recommends 1.49)

What is the problem

like image 867
Chani Avatar asked Oct 04 '22 17:10

Chani


1 Answers

Turning my comment into more of a complete answer. The boost::lock() functions are defined in boost/thread/locks.hpp. When you see the compiler error

error: ‘lock’ is not a member of ‘boost’

the compiler cannot find a function lock() in the boost namespace. The solution is to add #include <boost/thread/locks.hpp> in whatever translation unit you are compiling.

I don't see changes to this header from boost 1.49 to boost 1.53, though I didn't look extensively. It's possible include directives have changed.

Edit: Still the same in 1.67

like image 80
Sam Miller Avatar answered Oct 26 '22 21:10

Sam Miller