| 1 |
#include <pthread.h> |
| 2 |
#include <stdio.h> |
| 3 |
#include <unistd.h> |
| 4 |
|
| 5 |
int pipes[2]; |
| 6 |
|
| 7 |
void *Thread(void *x) { |
| 8 |
// wait for shutown signal |
| 9 |
while (read(pipes[0], &x, 1) != 1) { |
| 10 |
} |
| 11 |
close(pipes[0]); |
| 12 |
close(pipes[1]); |
| 13 |
return 0; |
| 14 |
} |
| 15 |
|
| 16 |
int main() { |
| 17 |
if (pipe(pipes)) |
| 18 |
return 1; |
| 19 |
pthread_t t; |
| 20 |
pthread_create(&t, 0, Thread, 0); |
| 21 |
// send shutdown signal |
| 22 |
while (write(pipes[1], &t, 1) != 1) { |
| 23 |
} |
| 24 |
pthread_join(t, 0); |
| 25 |
fprintf(stderr, "OK\n"); |
| 26 |
} |
| 27 |
|
| 28 |
/* { dg-prune-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */ |
| 29 |
/* { dg-output "OK" } */ |