blob: 8c5cb741f61f55da435f54995e6487ee58dc8991 [file] [log] [blame]
Dmitry Vyukov5cf2c462013-10-29 10:30:39 +00001// 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
6int Global;
7
8void *Thread1(void *x) {
9 sleep(1);
10 Global++;
11 return 0;
12}
13
14void *Thread2(void *x) {
15 pthread_setname_np(pthread_self(), "foobar2");
16 Global--;
17 return 0;
18}
19
20int 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