Is there any function to suspend a thread just like sleep() function. sleep(k) function is invoked inside a process to suspend the current process for 'k' seconds. I want a similar function but for thread level which can be invoked from the thread itself.
Code:#include <pthread.h> #include <stdio.h> void func(void) { while (1) { int data = rand()%100; printf("Current data is %d ...\n",data); /* here the thread should be suspended for 3 sec */ } } int main(void) { pthread_t thread1; srand(time(NULL)); printf("\n"); /* Spawn the Thread */ pthread_create( &thread1, NULL, func, NULL ); /* to join the thread */ pthread_join( thread1, NULL ); printf("\n"); return 0; }



LinkBack URL
About LinkBacks


