Draft
Fiber thread bridge for blocking_lock coop interleaving#119
blocking_lock coop interleaving#119Conversation
Agent-Logs-Url: https://github.com/camshaft/bach/sessions/bea21586-a66d-4044-9ce6-8a9a5d5d8736 Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/camshaft/bach/sessions/bea21586-a66d-4044-9ce6-8a9a5d5d8736 Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/camshaft/bach/sessions/be838bdd-d0df-4fa4-a28f-ccb7cade90e7 Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
camshaft
May 16, 2026 21:39
View session
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.
The panic/unwind PoC for
blocking_lockcan't resume at the call site — Rust'sasync fnstate machine poisons after an unwind, limiting it to manualFuture::pollimpls that restart cleanly. The correct fix is a thread-per-fiber bridge: the OS thread literally parks at theblocking_lockcall site via a condvar and resumes there when the coop scheduler grants the operation.Fiber infrastructure (
task/fiber.rs)FiberShared<R>— two condvars (fiber_wakeup,executor_wakeup) for executor↔fiber signaling;FiberStatusenum (WillRun / Running / Parked(Operation) / Done)FiberContexttrait +CURRENT_FIBERthread-local — letsblocking_lockdetect it is executing inside a fiberFiberFuture<R>: Future— drives the fiber; blocks the executor thread while the fiber runs (safe: Bach is single-threaded), returnsPoll::Pendingafter the fiber parks and registers itsOperationwith the coop schedulerspawn_fiber(f)— convenience wrapper overtask::spawn(FiberFuture::new(f))blocking_lock/blocking_lock_ownedIn fiber + active-coop context, always calls
park_for_operationbeforetry_lock— mirroring thelock_op.acquire().awaitin the asynclock()path. This makes every acquisition visible to the scheduler so all orderings are explored exhaustively. Falls back to the existing panic/unwind mechanism for non-fiber manualFuture::pollimpls (existing tests unchanged).Usage
The
mutex_blocking_lock_fibersnapshot test confirms both acquisition orderings are explored when two fiber tasks contend for the same mutex.