5

So i've been looking stuff about usleep() and all I have found to get rid of this is #define which i have done... Any ohter suggestion? I need to get rid of this warning... Or any ideas on how to use sleep with miliseconds.

#define _BSB_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <time.h>

int r = rand() % 1000 +1;
usleep(r*1000);        
pthread_mutex_lock (&count_mutex);
braindf
  • 734
  • 4
  • 14
user3785202
  • 67
  • 1
  • 1
  • 6

2 Answers2

7

You need to remove -std=c99 from your compiler command or use the _XOPEN_SOURCE macro before including unistd.h.

If you want you can use -std=gnu99 instead of -std=c99.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
2

nanosleep() worked for me:

On a relevant note: usleep() has been removed since POSIX-2008 and recommends to use nanosleep() instead.