Boost编译问题
我对提升非常非常新。据我了解,boost::mutex有成员lock()和unlock()。但是,我收到以下有关其后的函数的错误消息。我在源代码的同一文件夹中运行了“sudo apt-get install libboost-dev”命令。这也是我的教授给学生的代码。我确信它应该正确编译。任何帮助都会很棒!
错误消息:
matrix.cc:在函数“
void p_scalarproduct_t(int*, int*, int*, int, int, boost::mutex*)
”中:matrix.cc:75: 错误:“
class boost::mutex
”没有名为“lock
”的成员matrix.cc:77: 错误:“
class boost::mutex
”没有名为“unlock
”的成员matrix.cc:在函数“
int p_scalarproduct(int*, int*, int, int)”中:
matrix.cc:91: 错误:“
bind
”不是“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();
}
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 < e; k++)
tmp += a[k] * b[k];
lock->lock();
*c = *c + tmp;
lock->unlock();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在 boost 中锁定锁,您需要将其传递给关联的
scoped_lock
,在本例中为boost::mutex::scoped_lock
。因此,要锁定l_
,请执行以下操作:To lock a lock in boost, you need to pass it to the associated
scoped_lock
, in this caseboost::mutex::scoped_lock
. So to lock a lockl_
, do this: