1 /* { dg-shouldfail "tsan" } */
2 /* { dg-additional-options "-ldl" } */
5 #include "tsan_barrier.h"
7 static pthread_barrier_t barrier
;
10 void __attribute__((noinline
)) foo1() {
14 void __attribute__((noinline
)) bar1() {
15 volatile int tmp
= 42; (void)tmp
;
19 void __attribute__((noinline
)) foo2() {
20 volatile int v
= Global
; (void)v
;
23 void __attribute__((noinline
)) bar2() {
24 volatile int tmp
= 42; (void)tmp
;
28 void *Thread1(void *x
) {
29 barrier_wait(&barrier
);
34 void *Thread2(void *x
) {
36 barrier_wait(&barrier
);
40 void StartThread(pthread_t
*t
, void *(*f
)(void*)) {
41 pthread_create(t
, NULL
, f
, NULL
);
45 barrier_init(&barrier
, 2);
47 StartThread(&t
[0], Thread1
);
48 StartThread(&t
[1], Thread2
);
49 pthread_join(t
[0], NULL
);
50 pthread_join(t
[1], NULL
);
54 /* { dg-output "WARNING: ThreadSanitizer: data race.*" } */
55 /* { dg-output " Write of size 4 at .* by thread T1:(\n|\r\n|\r)" } */
56 /* { dg-output " #0 foo1.* .*(simple_stack.c:11|\\?{2}:0) (.*)" } */
57 /* { dg-output " #1 bar1.* .*(simple_stack.c:16|\\?{2}:0) (.*)" } */
58 /* { dg-output " #2 Thread1.* .*(simple_stack.c:30|\\?{2}:0) (.*)" } */
59 /* { dg-output " Previous read of size 4 at .* by thread T2:(\n|\r\n|\r)" } */
60 /* { dg-output " #0 foo2.* .*(simple_stack.c:20|\\?{2}:0) (.*)" } */
61 /* { dg-output " #1 bar2.* .*(simple_stack.c:25|\\?{2}:0) (.*)" } */
62 /* { dg-output " #2 Thread2.* .*(simple_stack.c:35|\\?{2}:0) (.*)" } */
63 /* { dg-output " Thread T1 \\(tid=.*, running\\) created by main thread at:(\n|\r\n|\r)" } */
64 /* { dg-output " #0 pthread_create .* (.*)" } */
65 /* { dg-output " #1 StartThread.* .*(simple_stack.c:41|\\?{2}:0) (.*)" } */
66 /* { dg-output " Thread T2 (.*) created by main thread at:(\n|\r\n|\r)" } */
67 /* { dg-output " #0 pthread_create .* (.*)" } */
68 /* { dg-output " #1 StartThread.* .*(simple_stack.c:41|\\?{2}:0) (.*)" } */