I am very very new to boost. As I understand it, boost::mutex has both members lock() and unlock(). However I am getting the following error messages regarding the function that follows them. I ran the 'sudo apt-get install libboost-dev' command within the same folder the source code. This also my professors code which was given to the students. I'm certain that it should be compiling correctly. Any help would be great!
Error Messages:
matrix.cc: In function ‘
void p_scalarproduct_t(int*, int*, int*, int, int, boost::mutex*)
’:matrix.cc:75: error: ‘
class boost::mutex
’ has no member named ‘lock
’matrix.cc:77: error: ‘
class boost::mutex
’ has no member named ‘unlock
’matrix.cc: In function ‘
int p_scalarproduct(int*, int*, int, int)
’:matrix.cc:91: error: ‘
bind
’ is not a member of ‘boost
’
Code:
void p_scalarproduct_t(int* c, int* a, int* b,
int s, int e, boost::mutex* lock)
{
int tmp;
tmp = 0;
for (int k = s; k <开发者_JS百科 e; k++)
tmp += a[k] * b[k];
lock->lock();
*c = *c + tmp;
lock->unlock();
}
To lock a lock in boost, you need to pass it to the associated scoped_lock
, in this case boost::mutex::scoped_lock
. So to lock a lock l_
, do this:
boost::mutex::scoped_lock l(l_)
精彩评论