Boost编译问题

发布于 2024-11-02 15:53:03 字数 935 浏览 6 评论 0原文

我对提升非常非常新。据我了解,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城空念 2024-11-09 15:53:03

要在 boost 中锁定锁,您需要将其传递给关联的 scoped_lock,在本例中为 boost::mutex::scoped_lock。因此,要锁定l_,请执行以下操作:

boost::mutex::scoped_lock l(l_)

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_)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文