gcc/testsuite/c-c++-common/tsan/pr68260.c
raw| 1 | /* PR sanitizer/68260 */ |
| 2 | |
| 3 | #include <pthread.h> |
| 4 | #include <stdbool.h> |
| 5 | |
| 6 | bool lock; |
| 7 | int counter; |
| 8 | |
| 9 | void * |
| 10 | tf (void *arg) |
| 11 | { |
| 12 | (void) arg; |
| 13 | while (__atomic_test_and_set (&lock, __ATOMIC_ACQUIRE)) |
| 14 | ; |
| 15 | ++counter; |
| 16 | __atomic_clear (&lock, __ATOMIC_RELEASE); |
| 17 | return (void *) 0; |
| 18 | } |
| 19 | |
| 20 | int |
| 21 | main () |
| 22 | { |
| 23 | pthread_t thr; |
| 24 | pthread_create (&thr, 0, tf, 0); |
| 25 | tf ((void *) 0); |
| 26 | pthread_join (thr, 0); |
| 27 | return 0; |
| 28 | } |