3

I just wanted to use nanosleep() but it seems not to be available in MingW ctime:

#include <ctime> //this is what I need, isn't it?

How can I use nanosleep on MingW? Thanks.

2
  • 1
    You could alternatively see if usleep is in unistd.h
    – Erik
    Apr 11, 2011 at 8:39
  • The code I have uses usleep() already. But I read that nanosleep() is better, so I wanted to use it instead of usleep (all the static analyzers throw warnings and usleep is declared as obsolete and there are also some articles on the web about it). Apr 11, 2011 at 8:41

2 Answers 2

1

Unfortunately, MinGW doesn't provide nanosleep().
MinGW only provides functions on this list, which are in the Microsoft API.

2
  • Thanks for the reply. Is there another alternative to usleep and nanosleep that works on both, Windows and Linux, without a lot of hacks and is not declared as obsolete? Apr 11, 2011 at 8:44
  • Unfortunately not. #ifdef is the best way to go.
    – Ben Stott
    Apr 11, 2011 at 8:45
1

In standard C++ library there is no such function (nanosleep). It is POSIX specific function declared in <time.h> not in <ctime>. You are under windows. Windows isn't POSIX. If you want to use POSIX library you need to install Cygwin.

1
  • 2
    Though it does claim to be POSIX-compliant (which is an utter lie though)
    – Ben Stott
    Apr 11, 2011 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.