xref: /haiku/src/tests/system/libroot/posix/tls_concurrency_test.c (revision 1a76488fc88584bf66b9751d7fb9b6527ac20d87)
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 
13 void *thread(void *ignored) {
14   th = 1;
15   return NULL;
16 }
17 
18 int 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