| 1 |
// PR sanitizer/64265 |
| 2 |
// { dg-shouldfail "tsan" } |
| 3 |
// { dg-additional-options "-fno-omit-frame-pointer -ldl" } |
| 4 |
|
| 5 |
#include <pthread.h> |
| 6 |
#include "tsan_barrier.h" |
| 7 |
|
| 8 |
static pthread_barrier_t barrier; |
| 9 |
int v; |
| 10 |
|
| 11 |
__attribute__((noinline, noclone)) int |
| 12 |
foo (int x) |
| 13 |
{ |
| 14 |
if (x < 99) |
| 15 |
throw x; |
| 16 |
barrier_wait (&barrier); |
| 17 |
v++; |
| 18 |
return x; |
| 19 |
} |
| 20 |
|
| 21 |
__attribute__((noinline, noclone)) void |
| 22 |
bar (void) |
| 23 |
{ |
| 24 |
for (int i = 0; i < 100; i++) |
| 25 |
try |
| 26 |
{ |
| 27 |
foo (i); |
| 28 |
} |
| 29 |
catch (int) |
| 30 |
{ |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
__attribute__((noinline, noclone)) void * |
| 35 |
tf (void *) |
| 36 |
{ |
| 37 |
bar (); |
| 38 |
return NULL; |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
main () |
| 43 |
{ |
| 44 |
pthread_t th; |
| 45 |
barrier_init (&barrier, 2); |
| 46 |
if (pthread_create (&th, NULL, tf, NULL)) |
| 47 |
return 0; |
| 48 |
v++; |
| 49 |
barrier_wait (&barrier); |
| 50 |
pthread_join (th, NULL); |
| 51 |
return 0; |
| 52 |
} |
| 53 |
|
| 54 |
// { dg-output "WARNING: ThreadSanitizer: data race.*#2 _?(tf|_Z2tfPv)" } |