我对 boost 非常非常陌生。据我了解,boost::mutex 有两个成员 lock() 和 unlock()。但是,我收到以下关于它们后面的函数的错误消息。我在与源代码相同的文件夹中运行了“sudo apt-get install libboost-dev”命令。这也是我教授给学生的代码。我确定它应该正确编译。任何帮助都会很棒!
错误信息:
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
’
代码:
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 < e; k++)
tmp += a[k] * b[k];
lock->lock();
*c = *c + tmp;
lock->unlock();
}
最佳答案
要在 boost 中锁定一个锁,您需要将其传递给关联的 scoped_lock
,在本例中为 boost::mutex::scoped_lock
。因此,要锁定一把锁 l_
,请执行以下操作:
boost::mutex::scoped_lock l(l_)
关于c++ - Boost 编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5759936/