What's changed
Refactoring
Extracted the double-checked locking + cache snapshot protocol used in every distribution into a single ThreadSafeCacheManager::withCacheSnapshot(SnapshotFn&&) helper (include/core/distribution_cache.h).
All Pattern A (scalar methods) and Pattern B (batch lambda) DCL blocks across 17 distribution source files are replaced with the unified helper — approximately 200 occurrences eliminated with no API or behavioural change.
No public API changes. Existing code compiles and runs identically.
Validation (M1 NEON + CI)
- 69/69 tests pass (46 correctness + 22 timing + 1 benchmark)
toctou_validator: 0 violations across all 19 distributions (10.6M concurrent reads)simd_verification: NEON speedups intact (PDF 6.5x, LogPDF 8.4x, CDF 3.2x)parallel_correctness_verification: 100% deterministic, 100% thread-safe- CI green on macOS (AppleClang/NEON), Linux (GCC/AVX2), Windows (MSVC/AVX-512)
Files changed
include/core/distribution_cache.h— addedwithCacheSnapshothelper- 17 distribution source files converted: beta, binomial, cauchy, discrete, exponential, gamma, gaussian, laplace, lognormal, negative_binomial, pareto, poisson, rayleigh, student_t, uniform, von_mises, weibull
Full changelog: https://github.com/OldCrow/libstats/blob/main/CHANGELOG.md