Commit bb1865b
Fix CallTraceHashTable race conditions and improve PREPARING state handling
This commit addresses critical race conditions in the CallTraceHashTable that
were causing "trace is NULL but hash exists" conditions and frequent log messages
during concurrent access.
Key improvements:
1. **Enhanced PREPARING state handling**: Instead of giving up after brief wait,
threads now properly wait (up to 1000 cycles) for preparing threads to complete
using architecture-specific spinPause() instructions for efficient waiting
2. **Race condition fixes**: Added key re-checking when trace is null to handle
transient races where keys are cleared during preparation failures
3. **Better memory ordering**: Added full memory barriers (SEQ_CST) when clearing
keys to ensure proper visibility of trace=null before key=0 operations
4. **Improved error handling**: Enhanced TEST_LOG messages with hash values and
slot numbers for better debugging of race conditions
5. **Timeout protection**: Added MAX_WAIT_CYCLES limit to prevent infinite waiting
in PREPARING state with graceful fallback to continue search
These fixes eliminate the frequent "markPreparing() failed" log messages observed
in concurrent tests while maintaining thread safety and performance. Verified by
clean gtest execution with no race condition messages.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 06f6ddc commit bb1865b
1 file changed
+47
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
207 | 209 | | |
208 | | - | |
209 | | - | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
211 | 234 | | |
212 | | - | |
213 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
214 | 239 | | |
215 | 240 | | |
216 | 241 | | |
217 | | - | |
218 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
219 | 251 | | |
220 | 252 | | |
221 | 253 | | |
| |||
228 | 260 | | |
229 | 261 | | |
230 | 262 | | |
231 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
232 | 266 | | |
233 | 267 | | |
234 | 268 | | |
| |||
253 | 287 | | |
254 | 288 | | |
255 | 289 | | |
256 | | - | |
| 290 | + | |
257 | 291 | | |
258 | | - | |
259 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
260 | 296 | | |
261 | 297 | | |
262 | 298 | | |
| |||
0 commit comments