Skip to content

Strand: per-strand implementation with shared mutex pool#271

Merged
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:pr/strand
Apr 29, 2026
Merged

Strand: per-strand implementation with shared mutex pool#271
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:pr/strand

Conversation

@sgerbino
Copy link
Copy Markdown
Collaborator

Replace the shared-impl strand pool with a per-strand implementation backed by a shared pool of mutexes. Removes the bucket-collision class where independent strands sharing a slot serialized against each other and compared equal.

  • strand_impl is per-strand, allocated by the service
  • Service holds a 193-mutex pool, hashed by impl address mixed with a per-service salt; collisions share a mutex, never pending work
  • Coroutine invoker keeps the impl alive via its frame parameter; invoker frames recycle through a single-slot per-service cache, closed under a kCacheClosed sentinel during shutdown
  • Service tracks live impls via intrusive_list for shutdown traversal
  • Service back-pointer in strand_impl is atomic so the destructor's load pairs with shutdown's store

Adds doc/strand-spec.md (design contract) and doc/strand-rationale.md (why the redesign was needed).

Tests: equality non-collision regression, cross-strand independence, transient strand lifetime via weak_ptr expiry, many-strands stress, deterministic mutex-pool collision isolation.

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented Apr 28, 2026

An automated preview of the documentation is available at https://271.capy.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-04-29 13:41:59 UTC

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented Apr 28, 2026

GCOVR code coverage report https://271.capy.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://271.capy.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://271.capy.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-04-29 13:57:17 UTC

Replace the shared-impl strand pool with a per-strand implementation
backed by a shared pool of mutexes. Removes the bucket-collision
class where independent strands sharing a slot serialized against
each other and compared equal.

- strand_impl is per-strand, allocated by the service
- Service holds a 193-mutex pool, hashed by impl address mixed with a
  per-service salt; collisions share a mutex, never pending work
- Coroutine invoker keeps the impl alive via its frame parameter;
  invoker frames recycle through a single-slot per-service cache,
  closed under a kCacheClosed sentinel during shutdown
- Service tracks live impls via intrusive_list for shutdown traversal
- Service back-pointer in strand_impl is atomic so the destructor's
  load pairs with shutdown's store

Adds doc/strand-spec.md (design contract) and doc/strand-rationale.md
(why the redesign was needed).

Tests: equality non-collision regression, cross-strand independence,
transient strand lifetime via weak_ptr expiry, many-strands stress,
deterministic mutex-pool collision isolation.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 94.28571% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.35%. Comparing base (2b3fe69) to head (84f3f1b).
⚠️ Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
src/ex/detail/strand_service.cpp 93.93% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #271      +/-   ##
===========================================
- Coverage    92.35%   92.35%   -0.01%     
===========================================
  Files          168      168              
  Lines         9354     9414      +60     
===========================================
+ Hits          8639     8694      +55     
- Misses         715      720       +5     
Flag Coverage Δ
linux 92.36% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
include/boost/capy/ex/strand.hpp 100.00% <100.00%> (ø)
src/ex/detail/strand_service.cpp 95.61% <93.93%> (-2.33%) ⬇️

... and 10 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b3fe69...84f3f1b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sgerbino sgerbino merged commit 4051c0c into cppalliance:develop Apr 29, 2026
39 checks passed
@sgerbino sgerbino deleted the pr/strand branch April 29, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants