boost::capy::safe_resume

Resume a coroutine handle with frame‐allocator TLS protection.

Synopsis

void
safe_resume(std::coroutine_handle<> h) noexcept;

Description

Saves the current thread‐local frame allocator before calling h.resume(), then restores it after the call returns. This prevents a resumed coroutine's await_resume from permanently overwriting the caller's allocator value.

Between a coroutine's resumption and its next child invocation, arbitrary user code may run. If that code resumes a coroutine from a different chain on this thread, the other coroutine's await_resume overwrites TLS with its own allocator. Without save/restore, the original coroutine's next child would allocate from the wrong resource.

Event loops, strand dispatch loops, and any code that calls .resume() on a coroutine handle should use this function instead of calling .resume() directly. See the Executor concept documentation for details.

Parameters

Name

Description

h

The coroutine handle to resume.