Julian Oes 91e25df7c4
parameters: fix data races in DynamicSparseLayer
Fix two concurrency bugs found with ThreadSanitizer:

1. size() and byteSize() read _next_slot/_n_slots without the mutex,
   racing with store(). Add AtomicTransaction to both.

2. _grow() with concurrent writers causes buffer overflow: _n_slots is
   read outside the lock for malloc sizing but inside the lock for
   memcpy, so another thread's growth can make memcpy exceed the
   allocation. On POSIX, hold the lock throughout _grow() since
   malloc/free work fine under a mutex. Keep the CAS-based approach
   on NuttX where malloc can't be called with IRQs disabled.

Add DynamicSparseLayerTest with concurrent stress tests that reproduce
both issues.

This issue was originally found while running the new SIH based CI
tests.
2026-02-16 20:59:12 +13:00
..