boost::mutex 在 Visual Studio 中支持 try_lock_for,但在 Xcode 中不支持
boost::mutex supports try_lock_for in Visual Studio, but not in Xcode
我正在使用Xcode 5.0和boost 1.54。以下代码使用 Visual Studio 2008 Sp1 可以很好地编译,但不能在 Xcode 中编译:
template <class Rep, class Period>
bool try_lock_for(const boost::chrono::duration<Rep, Period> &_rel_time)
{
return m_mutex.try_lock_for(_rel_time);
}
我在 Xcode 中收到错误"在 'boost::mutex'中没有名为'try_lock_until'的成员"。
我包括boost/mutex.hpp和boost/thread.hpp。Xcode 项目设置为使用 Apple LLVM 5.0 和 GNU99 C++方言。当我使用"try_lock_until(...)"时,我遇到了类似的编译错误。
似乎 boost::mutex 在两个平台上的定义不同。在Windows上,代码如下所示:
namespace detail
{
typedef ::boost::detail::basic_timed_mutex underlying_mutex;
}
class mutex:
public ::boost::detail::underlying_mutex
{
...
}
所以在 Windows boost::mutex 继承自定时互斥锁,但在 xcode 上它只是一个使用 pthreads 的类(不支持 try_for 等)。
那么在Windows和MacOS上使用boost互斥锁(带try_for)的正确方法是什么?任何帮助将不胜感激。
好的,解决了它(易于修复)。我用boost::timed_mutex替换了boost::mutex,现在VS2008和Xcode都在编译时没有代码错误。
相关文章:
- "error: no matching function for call to"构造函数错误
- 表示"accepting anything for this template argument" C++概念的通配符
- 如何在C++中从两个单独的for循环中添加两个数组
- 在Linux for Windows上编译C++代码时出错
- 调用专用模板时出错"no matching function for call to [...]"
- 为什么我的for循环不能正确获取argv
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 在基于范围的for循环中使用结构化绑定声明
- 通过for循环使用用户输入填充列表
- 使用for循环检查数组中的重复项
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 正在使用for循环创建QScatterSerie
- Python中的for循环与C++有何不同
- std::memory_order for std::atomic:<T>:wait
- 在更改for循环的第三部分后,未使用for循环结果
- 在 for 循环中查找问题时遇到困难
- 嵌套for循环C++的问题(初学者)
- std::lock() equivalent for boost::shared_mutex?