Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -lpthread -o %t && %deflake %run %t | FileCheck %s |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 2 | // Regression test for |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 3 | // https://github.com/google/sanitizers/issues/468 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 4 | // When the data race was reported, pthread_atfork() handler used to be |
| 5 | // executed which caused another race report in the same thread, which resulted |
| 6 | // in a deadlock. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 7 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 8 | |
| 9 | int glob = 0; |
| 10 | |
| 11 | void *worker(void *unused) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 12 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | glob++; |
| 14 | return NULL; |
| 15 | } |
| 16 | |
| 17 | void atfork() { |
| 18 | fprintf(stderr, "ATFORK\n"); |
| 19 | glob++; |
| 20 | } |
| 21 | |
| 22 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 23 | barrier_init(&barrier, 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 24 | pthread_atfork(atfork, NULL, NULL); |
| 25 | pthread_t t; |
| 26 | pthread_create(&t, NULL, worker, NULL); |
| 27 | glob++; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 28 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 29 | pthread_join(t, NULL); |
| 30 | // CHECK: ThreadSanitizer: data race |
| 31 | // CHECK-NOT: ATFORK |
| 32 | return 0; |
| 33 | } |