sleep( ) and usleep( ) problem
I have the following code that fails to compile. Sleep() just doesn't work and this version with usleep() gives a gcc personality error when compiling.
compile line is gcc -lpthread code.cpp #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h> void * thread_function (void * args) { while (1) { printf ("This is the thread speaking\n"); usleep (2*10000); } return NULL; } int main () { pthread_t thread; pthread_create (&thread, NULL, thread_function, NULL); while (1) { printf ("This is main talking\n"); usleep (2*10000); } return 0; } |
Sleep() is a MS function (ok, maybe it's a *nix function too, but I'm not aware of it). sleep() is a *nix function. it operates on seconds, so sleep(1) sleeps for one second.
I can compile the above code with g++ rather than gcc. is there a reason to use gcc? for the record, I tried the above code with both sleep and usleep - both worked when compiling with g++ |
Quote:
My bad, without knowing it you solved my problem. My makefile used gcc instead of g++ Thanks |
All times are GMT -5. The time now is 10:05 PM. |