Add awakened_from_remote() to bypass remote_ready_queue#1
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These mutex types are unused by the top-level project. Removes source files, headers, and references from CMakeLists.txt and all.hpp. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new scheduling extension point to allow certain scheduling algorithms to directly handle cross-thread wakeups, aiming to reduce latency/priority inversion caused by draining remote_ready_queue_ only on the owning thread.
Changes:
- Introduces
boost::fibers::algo::algorithm::awakened_from_remote()(defaultfalse) as an optional fast-path for remote scheduling. - Updates
scheduler::schedule_from_remote()to tryawakened_from_remote()before falling back toremote_ready_queue_. - Adds an optional
BOOST_FIBERS_WORKER_QUEUE_LOCKspinlock to protectworker_queue_for cross-thread attach/detach and adjusts related code paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/scheduler.cpp |
Uses the new awakened_from_remote() fast-path and adds optional locking around worker_queue_ operations. |
include/boost/fiber/scheduler.hpp |
Declares optional worker_splk_ and enforces multi-thread support when BOOST_FIBERS_WORKER_QUEUE_LOCK is enabled. |
include/boost/fiber/algo/algorithm.hpp |
Adds the new virtual awakened_from_remote() API and documents intended usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
08c6e7b to
d4627cd
Compare
Unused by the top-level project. Removes source, header, examples, and performance benchmarks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes source, header, examples, and performance benchmarks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes header, example, and include references from fiber.hpp and all.hpp. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes source, header, dedicated test files, and dead do_wait() references in fiber tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes fss.hpp, detail/fss.hpp, test files, and cleans fss_data_ from context.hpp and context.cpp. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes header, test files, and examples that solely used unbuffered_channel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unused by the top-level project. Removes rtm.hpp, spinlock_rtm.hpp, and strips BOOST_USE_TSX branches from spinlock.hpp. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d4627cd to
7f160f5
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
84fb830 to
dbaa8a9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
435a0f3 to
595be01
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if defined(BOOST_FIBERS_NO_SLEEP_QUEUE) | ||
| BOOST_ASSERT_MSG( false, "timed wait not supported with BOOST_FIBERS_NO_SLEEP_QUEUE"); | ||
| return false; | ||
| #else |
There was a problem hiding this comment.
With BOOST_FIBERS_NO_SLEEP_QUEUE defined, these wait_until() overloads assert and then return false. In release builds (asserts compiled out) this will silently report an immediate timeout, which can break higher-level primitives (e.g., condition_variable_any timed waits) in a hard-to-diagnose way. Consider making this a hard failure even in release (terminate/abort) or removing/ifdef’ing out timed-wait APIs when BOOST_FIBERS_NO_SLEEP_QUEUE is enabled so misuse can’t silently change semantics.
| #if defined(BOOST_FIBERS_NO_SLEEP_QUEUE) | ||
| BOOST_ASSERT_MSG( false, "timed wait not supported with BOOST_FIBERS_NO_SLEEP_QUEUE"); | ||
| return false; | ||
| #else |
There was a problem hiding this comment.
Same issue as the other wait_until() overload: under BOOST_FIBERS_NO_SLEEP_QUEUE this will silently behave as an immediate timeout in non-assert builds. Consider enforcing this at compile time or failing hard in all build modes to prevent subtle logic errors in timed-wait callers.
595be01 to
f8c75be
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f8c75be to
04b5548
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if defined(BOOST_FIBERS_AWAKENED_FROM_REMOTE) | ||
| // Let the algorithm handle cross-thread scheduling directly if it | ||
| // supports a thread-safe ready-queue (e.g. a shared priority queue). | ||
| // Gated by BOOST_FIBERS_AWAKENED_FROM_REMOTE because this path requires | ||
| // the atomic sleep_linked_ mirror (so sleep_is_linked() is safe to | ||
| // read remotely) and the worker_splk_ spinlock (so the subsequent | ||
| // ctx->detach() inside awakened_from_remote does not race the owning | ||
| // thread's attach of another fiber). | ||
| if ( ! ctx->is_context( type::pinned_context) && ! ctx->sleep_is_linked() ) { | ||
| if ( algo_->awakened_from_remote( ctx) ) { | ||
| algo_->notify(); | ||
| return; | ||
| } | ||
| } |
There was a problem hiding this comment.
The new cross-thread fast-path (awakened_from_remote() + atomic sleep_linked_ mirror) introduces new concurrency behavior but there are no tests exercising (1) that awakened_from_remote() is invoked for eligible remote wakeups, (2) that sleeping/pinned contexts correctly fall back to remote_ready_queue_, and (3) that no duplicate scheduling occurs under races. Given the existing multi-threaded test suite, it would be good to add a focused regression test with a custom algorithm overriding awakened_from_remote() and counters/assertions for these cases.
Extends algorithm::awakened_from_remote() so algorithms with a
thread-safe ready queue (e.g. a shared priority queue) can bypass the
per-thread remote_ready_queue_ FIFO on cross-thread wakeups. When
defined, BOOST_FIBERS_AWAKENED_FROM_REMOTE also enables:
- a spinlock around attach/detach_worker_context, so ctx->detach()
from a remote thread (as performed inside awakened_from_remote)
does not race the owning thread's attach for a different fiber.
- an atomic mirror of the sleep-queue link state on context, so
sleep_is_linked() can be queried from a remote thread without
touching the non-atomic intrusive sleep_hook_.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
04b5548 to
49a83fe
Compare
133ac78 to
a7c0273
Compare
Adds a virtual method algorithm::awakened_from_remote() that allows scheduling algorithms with thread-safe ready-queues to handle cross-thread fiber wakeups directly, avoiding the priority inversion caused by remote_ready_queue_ draining only on the owning thread.
Guarded by BOOST_FIBERS_WORKER_QUEUE_LOCK to protect worker_queue_ for cross-thread detach/attach with zero overhead when not needed.