Skip to content

fix(io_context): decouple concurrency_hint == 1 from lockless mode (#…#316

Draft
mvandeberg wants to merge 1 commit into
cppalliance:develop-2from
mvandeberg:pr/310-fix-concurrency-hint
Draft

fix(io_context): decouple concurrency_hint == 1 from lockless mode (#…#316
mvandeberg wants to merge 1 commit into
cppalliance:develop-2from
mvandeberg:pr/310-fix-concurrency-hint

Conversation

@mvandeberg

Copy link
Copy Markdown
Contributor

…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:

  • Remove the three hint == 1 -> single_threaded coupling sites (backend-tag template ctor, io_context(unsigned) ctor, and normalize_options, which is deleted along with the now-dead configure_single_threaded_() member).
  • Rename the public opt-in io_context_options::single_threaded -> single_threaded_unsafe so the lockless mode is loud and named, mirroring asio's ASIO_CONCURRENCY_HINT_UNSAFE convention. It remains the sole way to enable lockless mode (still gating the io_uring SINGLE_ISSUER flags).
  • Default ctor clamp max(2u, hardware_concurrency()) -> max(1u, ...): the "2" floor existed only to dodge the removed trap; floor at 1 still guards a 0 return.

Tests: the resolver/stream_file single-threaded restriction tests switch to explicit opts.single_threaded_unsafe; 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

@cppalliance-bot

cppalliance-bot commented Jul 10, 2026

Copy link
Copy Markdown

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-10 22:53:56 UTC

@mvandeberg mvandeberg force-pushed the pr/310-fix-concurrency-hint branch from 325c43c to 88bcce9 Compare July 10, 2026 21:12
…ppalliance#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:

- Remove the three hint == 1 -> single_threaded coupling sites (backend-tag
  template ctor, io_context(unsigned) ctor, and normalize_options, which
  is deleted along with the now-dead configure_single_threaded_() member).
- Rename the public opt-in io_context_options::single_threaded ->
  single_threaded_lockless, which remains the sole way to enable lockless
  mode (still gating the io_uring SINGLE_ISSUER flags). The explicit,
  descriptive name replaces an innocuous flag that read like a mere
  performance tweak.
- Default ctor clamp max(2u, hardware_concurrency()) -> max(1u, ...): the
  "2" floor existed only to dodge the removed trap; floor at 1 still guards
  a 0 return.

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 and benchmarks: header Doxygen (option, Thread Safety, default ctor),
the io-context and configuration guide pages, and all perf/bench/corosio
sources updated for the new option name.

Fixes cppalliance#310
@mvandeberg mvandeberg force-pushed the pr/310-fix-concurrency-hint branch from 88bcce9 to 9141d96 Compare July 10, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants