Add Linux IO::Event::Futex support - #210
Open
samuel-williams-shopify wants to merge 10 commits into
Open
Conversation
Signed-off-by: Samuel Williams <samuel.williams@shopify.com>
Signed-off-by: Samuel Williams <samuel.williams@shopify.com>
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
samuel-williams-shopify
force-pushed
the
add-futex
branch
from
August 30, 2026 00:23
ad228b2 to
936d3c1
Compare
Assisted-By: devx/065220da-7d48-4279-a513-aedd3bbfa4da
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.
Description
Add a Linux-only
IO::Event::Futexbacked by an aligned 32-bit word in anIO::Buffer. The platform primitive lives infutex.c/futex.h;uring.ccontains only the optional io_uring integration.The futex provides atomic value access, increment-and-wake signalling, single waits, and vector waits over up to
IO::Event::Futex::WAITV_LIMITfutex words.Futex#waitreturns whether it slept, whileFutex.wait_anyreturns the index of the futex that woke ornilwhen an expected value had already changed.When a fiber scheduler implements
futex_waitorfutex_waitv, the native methods delegate to it. The URing selector provides cancellable asynchronous implementations usingIORING_OP_FUTEX_WAITandIORING_OP_FUTEX_WAITV. Without a scheduler, the same native methods call the Linux futex syscalls while releasing the GVL. A scheduler that does not expose the corresponding optional hook raisesNotImplementedErrorrather than blocking its reactor thread.The class is defined only on Linux and does not require io_uring. The asynchronous selector hooks are exposed separately when io-event was compiled with a sufficiently recent liburing and the running kernel reports support for the corresponding opcodes.
Motivation
This provides a low-overhead shared-memory notification path for processes that already exchange state through
IO::Buffer. Vector waits allow a coordinator such as Fantail to sleep until any worker permit changes without polling every worker. Consumers can capability-detectIO::Event::Futexand use a portable notification mechanism when it is unavailable.Testing
Futex.wait_anyand selectorfutex_waitvsupport.The local Colima VM does not permit io_uring setup under its seccomp policy, so the native asynchronous runtime path is covered by the dedicated Linux CI job.