1#include <errno.h> 2#include <pthread.h> 3#include <stddef.h> 4#include <stdio.h> 5 6#define panic(n, str) if (n != 0) { perror(str); return 1; } 7 8#define numThreads 8 9#define loopCount 10000 10 11__thread int th = 0; 12 13void *thread(void *ignored) { 14 th = 1; 15 return NULL; 16} 17 18int main() { 19 pthread_t thr[numThreads]; 20 21 for (int i = 0; i < loopCount; i++) { 22 for (int j = 0; j < numThreads; j++) { 23 errno = pthread_create(&thr[j], NULL, thread, NULL); 24 panic(errno, "pthread_create"); 25 } 26 27 for (int j = 0; j < numThreads; j++) { 28 errno = pthread_join(thr[j], NULL); 29 panic(errno, "pthread_join"); 30 } 31 } 32 33 return 0; 34} 35