Open mbUSC opened 3 months ago
1. #define _GNU_SOURCE 1 2. 3. #include <stdio.h> 4. #include <pthread.h> 5. #include <unistd.h> 6. #include <coz.h> 7. 8. static const unsigned int NUM_ITERATIONS = 100000; 9. 10. void* threadA_fn(void* barrier) { 11. for (int i = 0; i < NUM_ITERATIONS; i++) { 12. usleep(2500); 13. pthread_barrier_wait(barrier); 14. COZ_PROGRESS; 15. } 16. } 17. 18. void* threadB_fn(void* barrier) { 19. for (int i = 0; i < NUM_ITERATIONS; i++) { 20. usleep(10000); 21. pthread_barrier_wait(barrier); 22. COZ_PROGRESS; 23. } 24. } 25. 26. int main(void) { 27. pthread_t threadA; 28. pthread_t threadB; 29. pthread_barrier_t barrier; 30. 31. pthread_barrier_init(&barrier, NULL, 2); 32. 33. pthread_create(&threadA, NULL, threadA_fn, &barrier); 34. pthread_create(&threadB, NULL, threadB_fn, &barrier); 35. 36. pthread_join(threadA, NULL); 37. pthread_join(threadB, NULL); 38. 39. pthread_barrier_destroy(&barrier); 40. }
Processor: 12th Gen Intel(R) Core(TM) i7-12800H 2.40 GHz Installed RAM: 32.0 GB (31.6 GB usable) OS: Windows 11 (WSL)
How to reproduce the problem
Environment
Processor: 12th Gen Intel(R) Core(TM) i7-12800H 2.40 GHz Installed RAM: 32.0 GB (31.6 GB usable) OS: Windows 11 (WSL)
Results from Coz