Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" } */
3 /* { dg-enable-nn-line-numbers "" } */
4
5 extern void acquire_lock_a(void);
6 extern void acquire_lock_b(void);
7
8 void foo ()
9 {
10 acquire_lock_a ();
11 acquire_lock_b ();
12 }
13
14 void bar ()
15 {
16 acquire_lock_b ();
17 acquire_lock_a (); /* { dg-warning "deadlock due to inconsistent lock acquisition order" } */
18 }
19
20 /* { dg-begin-multiline-output "" }
21 NN | acquire_lock_a ();
22 | ^~~~~~~~~~~~~~~~~
23 Thread: 'Thread 1'
24 'foo': event 1
25 |
26 | NN | {
27 | | ^
28 | | |
29 | | (1) entering 'foo'
30 |
31 +--> 'foo': event 2
32 |
33 | NN | acquire_lock_a ();
34 | | ^~~~~~~~~~~~~~~~~
35 | | |
36 | | (2) lock a is now held by thread 1
37 |
38
39 Thread: 'Thread 2'
40 'bar': event 3
41 |
42 | NN | {
43 | | ^
44 | | |
45 | | (3) entering 'bar'
46 |
47 +--> 'bar': event 4
48 |
49 | NN | acquire_lock_b ();
50 | | ^~~~~~~~~~~~~~~~~
51 | | |
52 | | (4) lock b is now held by thread 2
53 |
54
55 Thread: 'Thread 1'
56 'foo': event 5
57 |
58 | NN | acquire_lock_b ();
59 | | ^~~~~~~~~~~~~~~~~
60 | | |
61 | | (5) deadlocked due to waiting for lock b in thread 1 (acquired by thread 2 at (4))...
62 |
63
64 Thread: 'Thread 2'
65 'bar': event 6
66 |
67 | NN | acquire_lock_a ();
68 | | ^~~~~~~~~~~~~~~~~
69 | | |
70 | | (6) ...whilst waiting for lock a in thread 2 (acquired by thread 1 at (2))
71 |
72 { dg-end-multiline-output "" } */