Commit 3da513e
Fix TSAN race condition in FileLogger2 using base-from-member idiom
The root cause was that StatusChangeLogger subscribes to callbacks in
its constructor, but _p (the PImpl) wasn't initialized until after the
base class constructor completed. This meant callbacks could fire with
_p uninitialized.
Solution: Use the base-from-member idiom to ensure _p is initialized
BEFORE StatusChangeLogger. C++ initializes base classes in declaration
order, so by inheriting from FileLogger2PImplBase before StatusChangeLogger,
we guarantee _p exists when callbacks start firing.
Also wait for writer thread to be ready using condition_variable
synchronization before returning from the constructor.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent 6dfb1d5 commit 3da513e
File tree
3 files changed
+43
-13
lines changed- include/behaviortree_cpp/loggers
- src/loggers
- tests
3 files changed
+43
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
11 | 30 | | |
12 | 31 | | |
13 | 32 | | |
| |||
21 | 40 | | |
22 | 41 | | |
23 | 42 | | |
24 | | - | |
| 43 | + | |
25 | 44 | | |
26 | 45 | | |
27 | 46 | | |
| |||
36 | 55 | | |
37 | 56 | | |
38 | 57 | | |
39 | | - | |
40 | | - | |
| 58 | + | |
| 59 | + | |
41 | 60 | | |
42 | 61 | | |
43 | 62 | | |
| |||
58 | 77 | | |
59 | 78 | | |
60 | 79 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 80 | | |
65 | 81 | | |
66 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
37 | 46 | | |
38 | | - | |
| 47 | + | |
39 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
40 | 54 | | |
41 | 55 | | |
42 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
0 commit comments