GroveEngine/groveengine_architecture.html
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

617 lines
20 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GroveEngine - Modular C++ Architecture</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 40px 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #2d3436 0%, #000000 100%);
color: white;
padding: 60px 40px;
text-align: center;
}
.header h1 {
font-size: 3em;
margin-bottom: 10px;
font-weight: 700;
}
.header .subtitle {
font-size: 1.3em;
opacity: 0.9;
margin-bottom: 20px;
}
.header .tagline {
font-size: 1em;
opacity: 0.7;
font-style: italic;
}
.badges {
display: flex;
justify-content: center;
gap: 15px;
margin-top: 25px;
flex-wrap: wrap;
}
.badge {
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
padding: 8px 20px;
border-radius: 20px;
font-size: 0.9em;
border: 1px solid rgba(255,255,255,0.2);
}
.badge.hot {
background: rgba(255,100,100,0.2);
border-color: #ff6348;
}
.badge.experimental {
background: rgba(255,200,0,0.2);
border-color: #ffa502;
}
.content {
padding: 60px 40px;
}
.architecture {
margin-top: 40px;
}
.layer {
margin-bottom: 30px;
animation: fadeInUp 0.6s ease-out;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.layer-title {
font-size: 0.9em;
font-weight: 600;
color: #636e72;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 15px;
display: flex;
align-items: center;
}
.layer-title::before {
content: '';
width: 4px;
height: 20px;
background: #0984e3;
margin-right: 10px;
border-radius: 2px;
}
.modules-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.module {
background: linear-gradient(135deg, #f5f6fa 0%, #e4e6eb 100%);
border-radius: 12px;
padding: 25px;
border-left: 4px solid #0984e3;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.module::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, rgba(9,132,227,0.1) 0%, transparent 100%);
opacity: 0;
transition: opacity 0.3s ease;
}
.module:hover {
transform: translateY(-5px);
box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.module:hover::before {
opacity: 1;
}
.module.application {
border-left-color: #00b894;
background: linear-gradient(135deg, #e8f5f1 0%, #d4ebe5 100%);
}
.module.system {
border-left-color: #fdcb6e;
background: linear-gradient(135deg, #fff7e6 0%, #ffefd5 100%);
}
.module.core {
border-left-color: #6c5ce7;
background: linear-gradient(135deg, #f0eeff 0%, #e5deff 100%);
}
.module-name {
font-size: 1.3em;
font-weight: 600;
color: #2d3436;
margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
.module-status {
font-size: 0.7em;
padding: 4px 10px;
border-radius: 12px;
background: #00b894;
color: white;
font-weight: 500;
}
.module-status.todo {
background: #dfe6e9;
color: #636e72;
}
.module-description {
font-size: 0.9em;
color: #636e72;
line-height: 1.6;
margin-bottom: 15px;
}
.module-features {
list-style: none;
margin-top: 15px;
}
.module-features li {
font-size: 0.85em;
color: #2d3436;
padding: 5px 0;
padding-left: 20px;
position: relative;
}
.module-features li::before {
content: '▸';
position: absolute;
left: 0;
color: #0984e3;
font-weight: bold;
}
.connector {
text-align: center;
margin: 20px 0;
position: relative;
}
.connector::before {
content: '';
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 2px;
height: 40px;
background: linear-gradient(to bottom, #0984e3, transparent);
}
.connector-label {
display: inline-block;
background: white;
padding: 10px 25px;
border-radius: 20px;
font-size: 0.85em;
font-weight: 600;
color: #0984e3;
border: 2px solid #0984e3;
position: relative;
z-index: 1;
}
.iio-layer {
background: linear-gradient(135deg, #0984e3 0%, #0652a5 100%);
color: white;
padding: 30px;
border-radius: 12px;
margin: 20px 0;
text-align: center;
}
.iio-layer h3 {
font-size: 1.5em;
margin-bottom: 15px;
}
.iio-features {
display: flex;
justify-content: center;
gap: 30px;
flex-wrap: wrap;
margin-top: 20px;
}
.iio-feature {
font-size: 0.9em;
padding: 8px 20px;
background: rgba(255,255,255,0.1);
border-radius: 20px;
backdrop-filter: blur(10px);
}
.metrics {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-top: 40px;
}
.metric {
background: linear-gradient(135deg, #f5f6fa 0%, #e4e6eb 100%);
padding: 25px;
border-radius: 12px;
text-align: center;
border-top: 3px solid #0984e3;
}
.metric-value {
font-size: 2.5em;
font-weight: 700;
color: #0984e3;
margin-bottom: 5px;
}
.metric-label {
font-size: 0.9em;
color: #636e72;
font-weight: 500;
}
.footer {
background: #2d3436;
color: white;
padding: 30px;
text-align: center;
}
.footer-links {
display: flex;
justify-content: center;
gap: 20px;
margin-top: 15px;
flex-wrap: wrap;
}
.footer-link {
color: white;
text-decoration: none;
padding: 8px 20px;
background: rgba(255,255,255,0.1);
border-radius: 20px;
transition: all 0.3s ease;
}
.footer-link:hover {
background: rgba(255,255,255,0.2);
transform: translateY(-2px);
}
@media (max-width: 768px) {
.header h1 {
font-size: 2em;
}
.header .subtitle {
font-size: 1.1em;
}
.modules-grid {
grid-template-columns: 1fr;
}
.content {
padding: 40px 20px;
}
}
</style>
</head>
<body>
<div class="container">
<!-- Header -->
<div class="header">
<h1>🌳 GroveEngine</h1>
<div class="subtitle">Experimental Modular C++ Engine Architecture</div>
<div class="tagline">Blazing-fast hot-reload • Modular design • AI-assisted development</div>
<div class="badges">
<span class="badge hot">🔥 0.4ms Hot-Reload</span>
<span class="badge">🧩 Modular Architecture</span>
<span class="badge experimental">⚠️ Experimental</span>
<span class="badge">📜 Dual License (GPL v3 / Commercial 1%)</span>
</div>
</div>
<!-- Content -->
<div class="content">
<h2 style="text-align: center; color: #2d3436; margin-bottom: 50px;">Functional Architecture</h2>
<!-- Application Layer -->
<div class="layer">
<div class="layer-title">Application Layer</div>
<div class="modules-grid">
<div class="module application">
<div class="module-name">
Game Logic Module
<span class="module-status">Custom</span>
</div>
<div class="module-description">
Your game code - autonomous, hot-reloadable
</div>
<ul class="module-features">
<li>200-300 lines recommended</li>
<li>No infrastructure code</li>
<li>Pure business logic</li>
</ul>
</div>
<div class="module application">
<div class="module-name">
UI Module
<span class="module-status">Phase 7</span>
</div>
<div class="module-description">
Complete widget system with 10+ widget types
</div>
<ul class="module-features">
<li>Button, Panel, Label, Slider</li>
<li>Checkbox, TextInput, ProgressBar</li>
<li>Image, ScrollPanel, Tooltip</li>
<li>Retained mode rendering</li>
</ul>
</div>
<div class="module application">
<div class="module-name">
Custom Modules
<span class="module-status">Your Code</span>
</div>
<div class="module-description">
Add unlimited custom modules dynamically
</div>
<ul class="module-features">
<li>AI, Physics, Audio</li>
<li>Networking, Persistence</li>
<li>Hot-swappable</li>
</ul>
</div>
</div>
</div>
<!-- IIO Layer -->
<div class="connector">
<span class="connector-label">↓ Publish / Subscribe ↓</span>
</div>
<div class="iio-layer">
<h3>🔌 IIO Pub/Sub Messaging Layer</h3>
<div style="margin-top: 15px; font-size: 0.95em; opacity: 0.9;">
IntraIOManager • TopicTree Pattern Matching • Decoupled Communication
</div>
<div class="iio-features">
<div class="iio-feature">Sub-millisecond routing</div>
<div class="iio-feature">Wildcard patterns (render:*, ui:*)</div>
<div class="iio-feature">Zero module coupling</div>
<div class="iio-feature">Thread-safe design</div>
</div>
</div>
<div class="connector">
<span class="connector-label">↓ System Services ↓</span>
</div>
<!-- System Modules Layer -->
<div class="layer">
<div class="layer-title">System Modules Layer</div>
<div class="modules-grid">
<div class="module system">
<div class="module-name">
BgfxRenderer
<span class="module-status">Phase 8</span>
</div>
<div class="module-description">
Multi-backend 2D rendering (DX11/12, OpenGL, Vulkan, Metal)
</div>
<ul class="module-features">
<li>Sprite batching by texture</li>
<li>Tilemap instancing</li>
<li>Particle effects</li>
<li>Debug overlay (8x8 font)</li>
<li>RHI abstraction layer</li>
</ul>
</div>
<div class="module system">
<div class="module-name">
InputModule
<span class="module-status">Phase 1-3</span>
</div>
<div class="module-description">
Cross-platform input handling with SDL2
</div>
<ul class="module-features">
<li>Mouse (move, button, wheel)</li>
<li>Keyboard (keys, text input)</li>
<li>Thread-safe buffering</li>
<li>Gamepad: Phase 2 TODO</li>
</ul>
</div>
<div class="module system">
<div class="module-name">
NetworkIO
<span class="module-status todo">TODO</span>
</div>
<div class="module-description">
Distributed messaging and remote IPC
</div>
<ul class="module-features">
<li>Distributed pub/sub</li>
<li>Remote module communication</li>
<li>Network transparency</li>
</ul>
</div>
</div>
</div>
<!-- Core Engine Layer -->
<div class="connector">
<span class="connector-label">↓ Core Infrastructure ↓</span>
</div>
<div class="layer">
<div class="layer-title">Core Engine Infrastructure</div>
<div class="modules-grid">
<div class="module core">
<div class="module-name">
ModuleLoader
<span class="module-status">Validated</span>
</div>
<div class="module-description">
Dynamic .so/.dll hot-reload system
</div>
<ul class="module-features">
<li><strong>0.4ms average</strong> reload time</li>
<li>0.055ms best performance</li>
<li>100% state preservation</li>
<li>Cache bypass on reload</li>
</ul>
</div>
<div class="module core">
<div class="module-name">
SequentialModuleSystem
<span class="module-status">Active</span>
</div>
<div class="module-description">
Single-threaded module execution
</div>
<ul class="module-features">
<li>Deterministic order</li>
<li>Simple debugging</li>
<li>Low overhead</li>
<li>Multi-threaded: TODO</li>
</ul>
</div>
<div class="module core">
<div class="module-name">
Factory Pattern
<span class="module-status">Complete</span>
</div>
<div class="module-description">
Swappable infrastructure components
</div>
<ul class="module-features">
<li>EngineFactory</li>
<li>ModuleSystemFactory</li>
<li>IOFactory</li>
</ul>
</div>
</div>
</div>
<!-- Metrics -->
<h2 style="text-align: center; color: #2d3436; margin: 60px 0 30px;">Performance Metrics</h2>
<div class="metrics">
<div class="metric">
<div class="metric-value">0.4ms</div>
<div class="metric-label">Hot-Reload Average</div>
</div>
<div class="metric">
<div class="metric-value">0.055ms</div>
<div class="metric-label">Best Reload Time</div>
</div>
<div class="metric">
<div class="metric-value">20+</div>
<div class="metric-label">Integration Tests</div>
</div>
<div class="metric">
<div class="metric-value">100%</div>
<div class="metric-label">State Preservation</div>
</div>
<div class="metric">
<div class="metric-value">1%</div>
<div class="metric-label">Commercial Royalty</div>
</div>
<div class="metric">
<div class="metric-value">GPL v3</div>
<div class="metric-label">Open Source License</div>
</div>
</div>
</div>
<!-- Footer -->
<div class="footer">
<div>⚠️ <strong>Development Stage:</strong> Experimental • Non-deterministic • Optimized for rapid prototyping</div>
<div class="footer-links">
<a href="https://github.com/AlexisTrouve/GroveEngine" class="footer-link">📦 GitHub</a>
<a href="#" class="footer-link">📚 Documentation</a>
<a href="#" class="footer-link">💼 Commercial License</a>
<a href="mailto:alexistrouve.pro@gmail.com" class="footer-link">✉️ Contact</a>
</div>
<div style="margin-top: 20px; opacity: 0.7; font-size: 0.9em;">
GroveEngine © 2025 StillHammer • Where modules grow like trees in a grove 🌳
</div>
</div>
</div>
</body>
</html>