CheckForPthreads.c 511 B

123456789101112131415161718192021222324252627282930
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <unistd.h>
  4. void* runner(void*);
  5. int res = 0;
  6. int main()
  7. {
  8. pthread_t tid[2];
  9. pthread_create(&tid[0], 0, runner, (void*)1);
  10. pthread_create(&tid[1], 0, runner, (void*)2);
  11. usleep(1); // for strange behavior on single-processor sun
  12. pthread_join(tid[0], 0);
  13. pthread_join(tid[1], 0);
  14. return res;
  15. }
  16. void* runner(void* args)
  17. {
  18. int cc;
  19. for ( cc = 0; cc < 10; cc ++ )
  20. {
  21. printf("%d CC: %d\n", (int)args, cc);
  22. }
  23. res ++;
  24. return 0;
  25. }