Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use wait_for in c++0x thread

On gcc 4.4.6, RHEL 6.3 linux, i see the template in thread header

template<typename _Rep, typename _Period>
  inline void
  sleep_for(const chrono::duration<_Rep, _Period>& __rtime)

But if i try to use it in my application, i get error that sleep_for is not a member of std::this_thread

My application is simple as

#include <thread>
#include <chrono>

using namespace std;

int main()
{
  this_thread::sleep_for(chrono::seconds(1));
   return 0;
}
like image 267
Jimm Avatar asked Jan 31 '13 01:01

Jimm


1 Answers

When compiling add this parameter to your command line:

-D_GLIBCXX_USE_NANOSLEEP

So compile like this:

gcc -D_GLIBCXX_USE_NANOSLEEP test.cpp -o test

if using g++ you can use

g++ -std=gnu++0x -pthread test.cpp -o test
like image 83
Vahid Farahmand Avatar answered Oct 22 '22 11:10

Vahid Farahmand