PR tree-optimization/82549
[official-gcc.git] / libitm / testsuite / libitm.c / txrelease.c
blob37d6b2c9d009fc500112d35e9c49433276739b5f
1 /* This test triggers execution of the code that releases per-thread
2 transaction data when a thread exists, potentially repeatedly. However,
3 we currently cannot check whether the data has indeed been released. */
5 /* { dg-options "-pthread" } */
7 #include <stddef.h>
8 #include <stdlib.h>
9 #include <pthread.h>
11 static int round = 0;
12 static pthread_key_t key;
14 static void
15 thread_exit_handler(void *dummy __attribute__((unused)))
17 if (round == 0)
18 abort();
19 if (round == 1)
21 // ??? It would be good if we could check here that the transaction has
22 // indeed been released.
23 __transaction_atomic { round++; }
24 if (pthread_setspecific(key, &round))
25 abort();
27 // ??? It would be good if we could check here that the transaction has
28 // indeed been released (again).
31 static void *thread (void *dummy __attribute__((unused)))
33 if (pthread_key_create(&key, thread_exit_handler))
34 abort();
35 if (pthread_setspecific(key, &round))
36 abort();
37 __transaction_atomic { round++; }
38 return NULL;
41 int main()
43 pthread_t pt;
44 pthread_create(&pt, NULL, thread, NULL);
45 pthread_join(pt, NULL);
46 if (round != 2)
47 abort();
48 return 0;