Files
Library/docs/agent-workflow/tasks/M-CONTAINERS-02-03.md
T

38 lines
3.3 KiB
Markdown

# Containers Pool Lease Lifetimes, Budgets, and Non-Spinning Rings
Task ID: M-CONTAINERS-02, M-CONTAINERS-03
Phase: P1
Status: APPROVED
Contracts: C-01, C-04, C-05
## 1. Context and baseline
`include/Void/Containers/Pool.hpp` (`ObjectPool`, `FixedPool`) and `BufferPool.hpp` currently hold raw pool pointers in returned leases/deleters, leak slots on throwing construction, allocate heap nodes on buffer recycle, and lack admission/byte ceilings. `include/Void/Containers/Ring.hpp` currently spins indefinitely in `MpscRing::pop()` while waiting for `ready_[tail]` and lacks destruction of queued items on ring drop and explicit `close()`/`try_pop()` polling states.
## 2. Deliverables
- `src/Containers/module.cmake` declaring `INTERNAL_DEPS Core Memory`.
- Upgraded `include/Void/Containers/Pool.hpp`: stationary `std::shared_ptr<State>`, `std::pmr::memory_resource*` slab allocation, intrusive zero-alloc `noexcept` `Slot` recycling, throwing-ctor rollback, `ObjectPoolLimits`, `PoolError`, `try_acquire`, `live()`, `allocated_bytes()`, and exception-safe `FixedPool::try_acquire`.
- Upgraded `include/Void/Containers/BufferPool.hpp`: stationary `std::shared_ptr<State>`, O(1) power-of-two intrusive buckets (`buckets[65]`), checked `size_class` overflow, `Limits`, `BufferPoolError`, `try_acquire`, extended `Stats`, safe pool move/destruction while leases outlive owner.
- Upgraded `include/Void/Containers/Ring.hpp`: `PushStatus`, `PopStatus`, `PopResult<T>`, Vyukov per-slot sequence `MpscRing` non-spinning `try_pop()`/`close()`, destructor cleanup in `~SpscRing()`/`~MpscRing()`, keeping 1.x `push`/`pop`/`empty`/`full`/`capacity`.
- Expanded tests in `tests/standalone/Containers/{Pool,BufferPool,Ring}.cpp`.
## 3. Exact files and interfaces
- `src/Containers/module.cmake`
- `include/Void/Containers/Pool.hpp`
- `include/Void/Containers/BufferPool.hpp`
- `include/Void/Containers/Ring.hpp`
- `tests/standalone/Containers/{Pool,BufferPool,Ring}.cpp`
## 4. Edge cases
- Owner moved/destroyed while leases/buffers are still live (`~Buffer`/`~Ptr` frees directly via `State` and upstream resource with zero UAF and zero recycle heap allocations).
- `std::construct_at` throwing rolls back slot/budget accounting.
- Delayed MPSC producer paused inside move construction causes consumer `try_pop()` to return `PopStatus::pending` without blocking/spinning, then `PopStatus::ok` once producer completes.
- `> 4 * N` ring wraparound, `close()`, and `~SpscRing()`/`~MpscRing()` item destruction verified under TSan and ASan/UBSan.
## 5. Acceptance criteria
- `Pool*`, `BufferPool*`, and `Ring*` pass under `-DVOID_WARNINGS_AS_ERRORS=ON` and under Debug TSan (`-DVOID_ENABLE_TSAN=ON`).
## 6. Verification commands
```sh
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-p1-containers -G Ninja -DVOID_ENABLED_MODULES="Containers;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-p1-containers && /tmp/void-p1-containers/tests/VoidTests --filter "Pool*|BufferPool*|Ring*" && ctest --test-dir /tmp/void-p1-containers --output-on-failure --timeout 60'
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-p1-containers-tsan -G Ninja -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Containers;Testing" -DVOID_ENABLE_TSAN=ON -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-p1-containers-tsan && /tmp/void-p1-containers-tsan/tests/VoidTests --filter "Ring*"'
```