//------------------------------------------------------- // test.cpp //------------------------------------------------------- #include #include #include #include using namespace std; #define NUM_THREADS 2 void *PrintHello(void *threadid) { long int lastMillis = -1; for (;;) { timespec t; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t); long int millis = t.tv_nsec/(long int)1000000 + ((long int)(t.tv_sec)) * 1000; if (lastMillis != millis) { printf("%d> ms=%05d\n", (long)threadid, (int)millis); lastMillis = millis; } } } int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc, t; for(t=0;t < NUM_THREADS;t++){ printf("Creating thread %d\n", t); rc = pthread_create(&threads[t], NULL, PrintHello,(void *)t); if (rc){ printf("ERROR; return code from pthread_create()is %d\n", rc); exit(-1); } } cin >> ws; } //-------------------------------------------------------