2014-08-19 06:09:17 +08:00
|
|
|
// RUN: %clang_tsan -O1 %s -lpthread -o %t && %deflake %run %t | FileCheck %s
|
2014-05-14 00:17:54 +08:00
|
|
|
// Regression test for
|
2015-11-30 22:11:48 +08:00
|
|
|
// https://github.com/google/sanitizers/issues/468
|
2014-05-14 00:17:54 +08:00
|
|
|
// When the data race was reported, pthread_atfork() handler used to be
|
|
|
|
// executed which caused another race report in the same thread, which resulted
|
|
|
|
// in a deadlock.
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2014-05-14 00:17:54 +08:00
|
|
|
|
|
|
|
int glob = 0;
|
|
|
|
|
|
|
|
void *worker(void *unused) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2014-05-14 00:17:54 +08:00
|
|
|
glob++;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void atfork() {
|
|
|
|
fprintf(stderr, "ATFORK\n");
|
|
|
|
glob++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2014-05-14 00:17:54 +08:00
|
|
|
pthread_atfork(atfork, NULL, NULL);
|
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, NULL, worker, NULL);
|
|
|
|
glob++;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2014-05-14 00:17:54 +08:00
|
|
|
pthread_join(t, NULL);
|
|
|
|
// CHECK: ThreadSanitizer: data race
|
|
|
|
// CHECK-NOT: ATFORK
|
|
|
|
return 0;
|
|
|
|
}
|