Skip to content

make all non-forking rvalue awaitables movable#271

Merged
tzcnt merged 1 commit into
mainfrom
movable_rvalue_awaitables
Jul 14, 2026
Merged

make all non-forking rvalue awaitables movable#271
tzcnt merged 1 commit into
mainfrom
movable_rvalue_awaitables

Conversation

@tzcnt

@tzcnt tzcnt commented Jul 14, 2026

Copy link
Copy Markdown
Owner

The following rvalue-awaitable types have been made movable:

  • mutex::lock_scope()
  • mutex::co_unlock()
  • mutex::co_unlock_return()
  • semaphore::acquire_scope()
  • semaphore::co_release()
  • semaphoree::co_release_return()
  • rw_lock::lock_read()
  • rw_lock::lock_read_scope()
  • rw_lock::lock_write()
  • rw_lock::lock_write_scope()
  • atomic_condvar::await()
  • auto_reset_event::co_set()
  • manual_reset_event::co_set()

The purpose of this is to make all of them safe to capture as a temporary into another awaitable group which wraps them into a task by taking them as an argument. When this happens, they will be bound as values, so their lifetime is the same as the task.

mux.fork<0>(rwlock.lock_read()); // implicit task wrapper
co_await mux.fork_clang<1>(tmc::as_task(sem.acquire_scope())); // explicit task wrapper

After this, the only remaining non-movable rvalue-awaitables are those produced by an explicit fork primitive. For those, the rule remains as-before; you must assign them to a named variable before wrapping them into an awaitable group:

auto forked = tmc::spawn(some_task()).fork();
mux.fork<0>(std::move(forked));

(this fork behavior could be considered a footgun, and I'm considering making these lvalue awaitables, but that would be a substantial breaking change, so not today)

@tzcnt
tzcnt merged commit 5e3d4a9 into main Jul 14, 2026
58 of 61 checks passed
@tzcnt
tzcnt deleted the movable_rvalue_awaitables branch July 14, 2026 03:35
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.

1 participant