#include #include #include #include #include #define ONESEC 1000 #define NUM_ITERATIONS 20 #define THREAD_NUM 10 static int64_t omrtime_current_time_millis() { struct timeval tp; gettimeofday(&tp, NULL); return ((int64_t)tp.tv_sec) * 1000 + tp.tv_usec / 1000; } static void cpuLoad(void) { int64_t end = 0; int64_t start = omrtime_current_time_millis(); do { end = omrtime_current_time_millis(); /* usleep(1); */ } while ((end - start) < ONESEC); } static void *runTest(void *arg) { for (int i = 0; i < NUM_ITERATIONS; i++) { cpuLoad(); } return NULL; } int main() { int i; int rc; pthread_t thr[THREAD_NUM]; for (i = 0; i < THREAD_NUM; i++) { rc = pthread_create(&thr[i], NULL, runTest, NULL); if (rc != 0) { printf("pthread_create() failed: i=%d rc=%d\n", i, rc); return -1; } } for (i = 0; i < THREAD_NUM; i++) { pthread_join(thr[i], NULL); } puts("Finished"); return 0; }