GroveEngine/tests
StillHammer aefd7921b2 fix: Critical race conditions in ThreadedModuleSystem and logger
Fixed two critical race conditions that prevented multi-threaded module execution:

## Bug #1: ThreadedModuleSystem::registerModule() race condition

**Symptom:** Deadlock on first processModules() call
**Root Cause:** Worker thread started before being added to workers vector
**Fix:** Add worker to vector BEFORE spawning thread (src/ThreadedModuleSystem.cpp:102-108)

Before:
- Create worker → Start thread → Add to vector (RACE!)
- Thread accesses workers[index] before push_back completes

After:
- Create worker → Add to vector → Start thread (SAFE)
- Thread guaranteed to find worker in vector

## Bug #2: stillhammer::createLogger() race condition

**Symptom:** Deadlock when multiple threads create loggers simultaneously
**Root Cause:** Check-then-register pattern without mutex protection
**Fix:** Added static mutex around spdlog::get() + register_logger() (external/StillHammer/logger/src/Logger.cpp:94-96)

Before:
- Thread 1: check → create → register
- Thread 2: check → create → register (RACE on spdlog registry!)

After:
- Mutex protects entire check-then-register critical section

## Validation & Testing

Added comprehensive test suite:
- test_threaded_module_system.cpp (6 unit tests)
- test_threaded_stress.cpp (5 stress tests: 50 modules × 1000 frames)
- test_logger_threadsafe.cpp (concurrent logger creation)
- benchmark_threaded_vs_sequential.cpp (performance comparison)
- docs/THREADED_MODULE_SYSTEM_VALIDATION.md (full validation report)

All tests passing (100%):
- ThreadedModuleSystem:  0.15s
- ThreadedStress:  7.64s
- LoggerThreadSafe:  0.13s

## Impact

ThreadedModuleSystem now PRODUCTION READY:
- Thread-safe module registration
- Stable parallel execution (validated with 50,000+ operations)
- Hot-reload working (100 cycles tested)
- Logger thread-safe for concurrent module initialization

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 07:37:31 +07:00
..
assets/textures feat: Complete Phase 6.5 - Comprehensive BgfxRenderer testing 2025-11-29 22:56:29 +08:00
benchmarks fix: Critical race conditions in ThreadedModuleSystem and logger 2026-01-19 07:37:31 +07:00
demo feat: Add UIModule interactive showcase demo 2025-11-29 08:52:25 +08:00
helpers fix: IntraIOManager batch thread + AutoCompiler Windows support 2025-12-31 09:44:37 +07:00
hotreload feat: Windows portage + Phase 4 SceneCollector integration 2025-11-27 09:48:14 +08:00
integration fix: Critical race conditions in ThreadedModuleSystem and logger 2026-01-19 07:37:31 +07:00
mocks feat: Complete Phase 6.5 - Comprehensive BgfxRenderer testing 2025-11-29 22:56:29 +08:00
modules fix: IntraIOManager batch thread + AutoCompiler Windows support 2025-12-31 09:44:37 +07:00
unit feat: Complete Phase 6.5 - Comprehensive BgfxRenderer testing 2025-11-29 22:56:29 +08:00
visual fix: Critical race conditions in ThreadedModuleSystem and logger 2026-01-19 07:37:31 +07:00
CMakeLists.txt fix: Critical race conditions in ThreadedModuleSystem and logger 2026-01-19 07:37:31 +07:00
profile_memory_leak.cpp feat: Add integration tests 8-10 & fix CTest configuration 2025-11-19 07:34:15 +08:00