| 1 |
/* { dg-set-target-env-var TSAN_OPTIONS "halt_on_error=1" } */ |
| 2 |
/* { dg-shouldfail "tsan" } */ |
| 3 |
/* { dg-additional-options "-ldl" } */ |
| 4 |
|
| 5 |
#include <pthread.h> |
| 6 |
#include <unistd.h> |
| 7 |
#include "tsan_barrier.h" |
| 8 |
|
| 9 |
#define MAX_ITERATIONS_NUMBER 1 |
| 10 |
#define SLEEP_STEP 128000 |
| 11 |
|
| 12 |
static pthread_barrier_t barrier; |
| 13 |
unsigned int delay_time = 1000; |
| 14 |
|
| 15 |
static inline void delay () { |
| 16 |
usleep(delay_time); |
| 17 |
} |
| 18 |
|
| 19 |
extern int main_1(); |
| 20 |
|
| 21 |
int main() { |
| 22 |
barrier_init(&barrier, 2); |
| 23 |
int i; |
| 24 |
for (i = 0; i < MAX_ITERATIONS_NUMBER; i++) { |
| 25 |
main_1(); |
| 26 |
delay_time += delay_time < 256000 ? delay_time : SLEEP_STEP; |
| 27 |
} |
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
int Global; |
| 32 |
|
| 33 |
void *Thread1(void *x) { |
| 34 |
barrier_wait(&barrier); |
| 35 |
delay(); |
| 36 |
Global = 42; |
| 37 |
return NULL; |
| 38 |
} |
| 39 |
|
| 40 |
void *Thread2(void *x) { |
| 41 |
Global = 43; |
| 42 |
barrier_wait(&barrier); |
| 43 |
return NULL; |
| 44 |
} |
| 45 |
|
| 46 |
int main_1() { |
| 47 |
pthread_t t[2]; |
| 48 |
pthread_create(&t[0], NULL, Thread1, NULL); |
| 49 |
pthread_create(&t[1], NULL, Thread2, NULL); |
| 50 |
pthread_join(t[0], NULL); |
| 51 |
pthread_join(t[1], NULL); |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
/* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */ |