Dmitry Vyukov | 5cf2c46 | 2013-10-29 10:30:39 +0000 | [diff] [blame^] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s |
| 2 | #include <pthread.h> |
| 3 | #include <stdio.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | int Global; |
| 7 | |
| 8 | void *Thread1(void *x) { |
| 9 | sleep(1); |
| 10 | Global++; |
| 11 | return 0; |
| 12 | } |
| 13 | |
| 14 | void *Thread2(void *x) { |
| 15 | pthread_setname_np(pthread_self(), "foobar2"); |
| 16 | Global--; |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | int main() { |
| 21 | pthread_t t[2]; |
| 22 | pthread_create(&t[0], 0, Thread1, 0); |
| 23 | pthread_create(&t[1], 0, Thread2, 0); |
| 24 | pthread_setname_np(t[0], "foobar1"); |
| 25 | pthread_join(t[0], NULL); |
| 26 | pthread_join(t[1], NULL); |
| 27 | } |
| 28 | |
| 29 | // CHECK: WARNING: ThreadSanitizer: data race |
| 30 | // CHECK: Thread T1 'foobar1' |
| 31 | // CHECK: Thread T2 'foobar2' |
| 32 | |