如何在 C++0X 线程中使用wait_for
how to use wait_for in c++0x thread
在 gcc 4.4.6、RHEL 6.3 Linux 上,我在线程标头中看到模板
template<typename _Rep, typename _Period>
inline void
sleep_for(const chrono::duration<_Rep, _Period>& __rtime)
但是,如果我尝试在我的应用程序中使用它,我会收到错误sleep_for is not a member of std::this_thread
我的应用程序很简单
#include <thread>
#include <chrono>
using namespace std;
int main()
{
this_thread::sleep_for(chrono::seconds(1));
return 0;
}
编译时将此参数添加到命令行:
-D_GLIBCXX_USE_NANOSLEEP
所以像这样编译:
gcc -D_GLIBCXX_USE_NANOSLEEP test.cpp -o test
如果使用 G++,您可以使用
g++ -std=gnu++0x -pthread test.cpp -o test
相关文章:
- "error: no matching function for call to"构造函数错误
- 表示"accepting anything for this template argument" C++概念的通配符
- 如何在C++中从两个单独的for循环中添加两个数组
- std::condition_variable::wait()如何评估给定的谓词
- 在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循环中使用结构化绑定声明
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 通过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循环结果
- 用于线程"Wait for Alert/Event"的标准库版本