Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 2 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 4 | #if defined(__FreeBSD__) |
| 5 | #include <pthread_np.h> |
| 6 | #define pthread_setname_np pthread_set_name_np |
| 7 | #endif |
| 8 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | int Global; |
| 10 | |
| 11 | void *Thread1(void *x) { |
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 | Global++; |
| 14 | return 0; |
| 15 | } |
| 16 | |
| 17 | void *Thread2(void *x) { |
| 18 | pthread_setname_np(pthread_self(), "foobar2"); |
| 19 | Global--; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 20 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 25 | barrier_init(&barrier, 3); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 26 | pthread_t t[2]; |
| 27 | pthread_create(&t[0], 0, Thread1, 0); |
| 28 | pthread_create(&t[1], 0, Thread2, 0); |
| 29 | pthread_setname_np(t[0], "foobar1"); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 30 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 31 | pthread_join(t[0], NULL); |
| 32 | pthread_join(t[1], NULL); |
| 33 | } |
| 34 | |
| 35 | // CHECK: WARNING: ThreadSanitizer: data race |
| 36 | // CHECK: Thread T1 'foobar1' |
| 37 | // CHECK: Thread T2 'foobar2' |