support async futex#55
Closed
wokron wants to merge 3 commits into
Closed
Conversation
There was a problem hiding this comment.
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 viainclude/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
queueexample 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_()callsdetail::Context::current().runtime()->pend_work(). This makes the wait path depend on TLS context and will crash ifContext::current().runtime()is null (e.g., if someone ever usesAsyncFutexoutside a runningRuntime, or in future refactors). SinceWaitFinishHandlealready stores aruntime_(andawait_suspend/register_operationalready obtained aruntime), prefer using that runtime pointer (e.g., passRuntime*intorequest_wait_()and use it forpend_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.
1adf296 to
0533b5b
Compare
Member
Author
|
See #99 |
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.
No description provided.