【问题标题】:boost::mutex::timed_lock not on Linuxboost::mutex::timed_lock 不在 Linux 上
【发布时间】:2013-12-05 20:33:02
【问题描述】:

我有一个使用 VS2010 开发的应用程序,它使用 Boost.Thread 1.48。

目前我正在尝试将应用程序移植到 Linux(在 Debian 7 上运行)。

当我尝试使用 GCC 4.6 或 clang 编译它时,我收到以下错误

error: ‘class boost::mutex’ has no member named ‘timed_lock’

我必须设置任何预处理器定义或编译器标志吗?

编辑: 好的,我找到了问题。我使用了以下内容:

我的文件.h:

boost::mutex myMutex;

我的文件.cpp

if(myMutex.timed_lock(boost::posix_time::millisec(10000)))
{
    // Do stuff
    // ...
    // ...

    myMutex.unlock();
    return true;
}

myMutex.unlock();
return false;

这适用于 VS2008/2010。 在 Linux 下,我不得不将标题更改为:

boost::timed_mutex myMutex;

我还是不太清楚,是什么原因。

【问题讨论】:

  • 你在 Debian 中使用的是什么 boost 版本?
  • 我从头开始构建 Boost 1.48 并指向包含 dir 和 lib dir。

标签: c++ linux gcc boost-thread


【解决方案1】:

在 windows 平台中 boost::mutex 和 boost::timed_mutex 共享相同的实现。这是一个实现细节。

如果你想使用 timed_lock() 作为 Boost.Thread 文档,你应该使用 boost::time_mutex。

http://www.boost.org/doc/libs/1_55_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_types.timed_mutex

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2011-12-10
    相关资源
    最近更新 更多