Commit 0fa504d
Add thread-safety to Truthiness algorithm statistics tracking (#2179)
The Truthiness algorithm accumulates statistics in mutable member
variables from a const `process()` method, creating race conditions when
called concurrently from multiple threads.
## Changes
- **`m_event_count`**: Changed from `uint64_t` to
`std::atomic<uint64_t>` for lock-free atomic operations
- **`m_stats_mutex`**: Added mutex to protect `m_average_truthiness`
updates during the online average calculation
- **Accessors**: `getAverageTruthiness()` now locks, `getEventCount()`
uses atomic `.load()`
```cpp
// In process()
{
std::lock_guard<std::mutex> lock(m_stats_mutex);
m_event_count++;
m_average_truthiness += (truthiness - m_average_truthiness) / m_event_count;
}
```
Pattern follows existing thread-safe implementations in the codebase
(e.g., `UniqueIDGenSvc`).
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: wdconinc <[email protected]>1 parent 5c08168 commit 0fa504d
2 files changed
+14
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
140 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
141 | 144 | | |
142 | 145 | | |
143 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| |||
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | | - | |
59 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
0 commit comments