Skip to content

support async futex#55

Closed
wokron wants to merge 3 commits into
masterfrom
async-futex
Closed

support async futex#55
wokron wants to merge 3 commits into
masterfrom
async-futex

Conversation

@wokron
Copy link
Copy Markdown
Member

@wokron wokron commented Feb 23, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a user-space coroutine-friendly futex (condy::AsyncFutex) and adds coverage + examples demonstrating higher-level synchronization primitives (semaphore/mutex) and a producer/consumer queue built on top of it.

Changes:

  • Add condy::AsyncFutex<T> awaitable synchronization primitive (include/condy/futex.hpp) and export it via include/condy.hpp.
  • Add a new doctest suite covering basic wait/notify, notify-all, cross-thread notify, cancellation, and a queue scenario (tests/test_futex.cpp).
  • Add a new queue example plus build/docs wiring (examples/queue.cpp, examples/CMakeLists.txt, docs/examples.md).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_futex.cpp New tests for AsyncFutex, plus queue-based integration scenario.
include/condy/futex.hpp New condy::AsyncFutex implementation (wait/notify + cancellation).
include/condy.hpp Exports the new futex header from the umbrella include.
examples/queue.cpp New queue example built on AsyncFutex-based semaphore/mutex.
examples/CMakeLists.txt Adds queue example target; fixes formatting on an existing target line.
docs/examples.md Documents the new queue.cpp example.
Comments suppressed due to low confidence (1)

include/condy/futex.hpp:87

  • request_wait_() calls detail::Context::current().runtime()->pend_work(). This makes the wait path depend on TLS context and will crash if Context::current().runtime() is null (e.g., if someone ever uses AsyncFutex outside a running Runtime, or in future refactors). Since WaitFinishHandle already stores a runtime_ (and await_suspend/register_operation already obtained a runtime), prefer using that runtime pointer (e.g., pass Runtime* into request_wait_() and use it for pend_work()).
    bool request_wait_(WaitFinishHandle *handle) noexcept {
        std::lock_guard<std::mutex> lock(mutex_);
        auto current_value = futex_.load(std::memory_order_relaxed);
        if (current_value != handle->get_old_value()) {
            return false; // No need to wait
        }
        wait_awaiters_.push_back(handle);
        detail::Context::current().runtime()->pend_work();
        return true;
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/condy/futex.hpp
Comment thread tests/test_futex.cpp Outdated
Comment thread tests/test_futex.cpp Outdated
Comment thread tests/test_futex.cpp Outdated
Comment thread examples/queue.cpp Outdated
@wokron wokron force-pushed the async-futex branch 3 times, most recently from 1adf296 to 0533b5b Compare March 5, 2026 07:04
@wokron
Copy link
Copy Markdown
Member Author

wokron commented Apr 27, 2026

See #99

@wokron wokron closed this Apr 27, 2026
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.

2 participants