Skip to content

Multi-reactor threading with socket hand-off inbox - #9

Merged
AgentDudu merged 2 commits into
developfrom
feature/reactor-threading
Oct 20, 2026
Merged

AgentDudu merged 2 commits into
developfrom
feature/reactor-threading

Conversation

@AgentDudu

Copy link
Copy Markdown
Owner

Acceptor + K reactor threads; per-connection ownership, no shared connection state.

  • net::Wakeup: socketpair (POSIX) / loopback pair (Winsock) wake for the inbox
  • EINTR from accept poll no longer double-joins reactors (Linux-only crash:
    pthread_join EINVAL via run()); stopAll is joinable()-guarded
  • 3 new tests: 12 conns x 2 requests across 4 reactors, stop-drain on every
    reactor, pipelined storms with fresh mid-flight clients (CI TSan exercises)
  • also commits the MSVC/MinGW CMakePresets that never landed earlier (CI
    configures with explicit flags, so only local ck.ps1 -Toolchain was blind)

The MSVC/MinGW presets existed only in the working tree; CI passed because it
configures with explicit flags. Now ck.ps1 -Toolchain works from a clean clone.
Server::run now runs an acceptor (the calling thread) plus K reactor threads
(threads=0 -> hardware_concurrency). Accepted sockets move to a reactor over a
mutex-guarded inbox woken by net::Wakeup (POSIX socketpair; Windows loopback
pair) - a Connection is owned by exactly one reactor, so connection state
stays lock-free. Round-robin placement; deadlines, backpressure and drain-then-
drop stop are per-reactor.

Fix found on the Linux gate: SIGINT turns accept poll into EINTR; the error
path used to join reactors and the normal stop path joined them again ->
pthread_join EINVAL out of run(). Interrupted now just re-checks stop, and
stopAll joins only joinable threads.

Tests: cross-reactor keep-alive (12 conns / 4 reactors), stop-drain across all
reactors, pipelined storm with interleaved fresh clients - all under CI TSan.
Linux gates re-run under Docker Desktop after podman/VS disappeared from this
machine; clang-format now invoked via LLVM path in the local gate.
@AgentDudu
AgentDudu force-pushed the feature/reactor-threading branch from ef6e5a7 to 7e64e6e Compare October 20, 2026 11:10
@AgentDudu
AgentDudu merged commit 4093985 into develop Oct 20, 2026
3 checks passed
@AgentDudu
AgentDudu deleted the feature/reactor-threading branch October 20, 2026 11:14
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.

1 participant