fix(io_context): decouple concurrency_hint == 1 from lockless mode (#…#316
Merged
mvandeberg merged 1 commit intoJul 15, 2026
Merged
Conversation
|
An automated preview of the documentation is available at https://316.corosio.prtest3.cppalliance.org/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-07-15 15:42:05 UTC |
mvandeberg
force-pushed
the
pr/310-fix-concurrency-hint
branch
2 times, most recently
from
July 10, 2026 22:48
88bcce9 to
9141d96
Compare
mvandeberg
marked this pull request as ready for review
July 13, 2026 16:33
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop-2 #316 +/- ##
==========================================
Coverage 77.89% 77.89%
==========================================
Files 96 96
Lines 7139 7139
Branches 1744 1744
==========================================
Hits 5561 5561
Misses 1076 1076
Partials 502 502
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
mvandeberg
force-pushed
the
pr/310-fix-concurrency-hint
branch
2 times, most recently
from
July 15, 2026 15:07
65d8102 to
470dbfb
Compare
…er forces lockless mode (cppalliance#310) `concurrency_hint` is now purely a performance hint (how many threads are expected to call `run()`); it never changes the thread-safety contract. In particular `concurrency_hint == 1` keeps full thread safety and full multi-thread utilization. Thread safety is governed by a new `io_context_options::locking` tier (`locking_mode` enum), replacing the `single_threaded` bool and mirroring Boost.Asio's SAFE / UNSAFE_IO / UNSAFE: - `safe` (default): all locks enabled; any thread may run and post. - `unsafe_io`: per-descriptor I/O locks off, scheduler locking kept; the context must be single-threaded, but resolver and POSIX file services remain available. - `unsafe`: all locks off; single-threaded, and DNS/POSIX file I/O return `operation_not_supported`. Implementation: - Scheduler threading is configured through a decomposed `threading_config` (scheduler_locking / reactor_io_locking / one_thread), replacing the coarse `configure_single_threaded` / `is_single_threaded`. The reactor, io_uring, and IOCP schedulers honor it. - `one_thread` engages a single-run-thread fast path (eliding inter-run-thread wakeups); it is set only for the lockless tiers, so the safe tier retains full multi-thread utilization at any hint. - The effective concurrency hint is normalized to 1 for the lockless tiers, driving the reactor inline-completion budget heuristic and, on IOCP, `NumberOfConcurrentThreads`. - Resolver and POSIX file services gate `operation_not_supported` on scheduler locking being disabled (the `unsafe` tier only), so they stay available under `unsafe_io`. - io_uring `SINGLE_ISSUER`/`DEFER_TASKRUN` and the eventfd wake elision are keyed on the ring being a single user (the lockless tiers). - The default constructor uses `max(1u, hardware_concurrency())`. Tests cover the tiers (unsafe_io keeps services available; unsafe restricts them), hint==1 thread safety and peer utilization across multiple run threads, and effective-hint normalization. Benchmarks, guide pages, and docstrings are updated for the new option. Fixes cppalliance#310.
mvandeberg
force-pushed
the
pr/310-fix-concurrency-hint
branch
from
July 15, 2026 15:35
470dbfb to
5194a70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…310)
A concurrency_hint of 1 silently enabled full single-threaded lockless mode: scheduler mutex/condvar, per-descriptor locks, IOCP dispatch mutex, and io_uring ring/dispatch mutexes were all disabled, plus io_uring got SINGLE_ISSUER/DEFER_TASKRUN. This made cross-thread post() undefined behavior, contrary to asio (where a plain integer hint never disables locking) and to what migrating users expect.
A hint now only tunes performance and never changes the safety contract:
Tests: the resolver/stream_file single-threaded restriction tests switch to explicit opts.single_threaded_lockless; new testHintOneIsThreadSafe proves cross-thread post() into a hint == 1 context is TSan-clean across all backends (verified: fails under TSan with the coupling restored).
Docs: header Doxygen (option, Thread Safety, default ctor) plus the io-context and configuration guide pages updated.
Fixes #310