Serialize Box3D world create and destroy behind one process-wide lock

b3CreateWorld/b3DestroyWorld scan and rewrite Box3D's global world pool with
no synchronization; concurrent creation crashed the host (0xC000001D). All
five call sites (SoA world, retained session, pair step, torque lifetime) now
go through one lock owned by ymir_box3d.c (SRWLOCK on Windows, pthread mutex
elsewhere). Adds a multi-thread create/step/dispose test, which aborts the
test host without the lock; drops the serial-test assembly attribute.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-19 21:11:08 +01:00
commit db09805aba
6 changed files with 105 additions and 12 deletions

View file

@ -62,6 +62,10 @@ Unity consumption is unrun; cross-platform bit-identity is unclaimed.
`bin\$(Configuration)\` on every platform: `CMakeLists.txt` writes `bin/$<CONFIG>/` and the csproj passes `-DCMAKE_BUILD_TYPE=$(Configuration)`, so single- and multi-config generators land in the same place.
- Windows run: MinGW gcc with `CMAKE_GENERATOR="Ninja Multi-Config" CC=gcc`; `Ymir.Box3D.Soa.Tests` passes.
Linux run (Yggdrasil, default generator, gcc): the same tests pass and emit `bin/Debug/libymir_box3d.so`. macOS is unrun.
- Threading: creating and destroying worlds is safe from any number of threads at once (a process-wide lock in the native
layer serializes `b3CreateWorld`/`b3DestroyWorld`, which otherwise scan and rewrite Box3D's global world pool unsynchronized;
the retained session and pair-step paths take the same lock). Stepping distinct worlds concurrently is safe. A single world
is still not thread-safe. `Box3DSoaConcurrentCreateTests` creates, steps and disposes worlds from eight threads.
- `Box3DSoaWorld` is not thread-safe: `Dispose` must not race `Step` or a lane read. A `Box3DSoaView` refuses
to hand out a lane (ObjectDisposedException) once its world is disposed, and a `default` view refuses with
InvalidOperationException. The check guards obtaining a span, not a span already held: a span taken from a