r/wg21
P3980R0 - Task's Allocator Use WG21
Posted by u/task_allocator_watcher · 7 hr. ago

Document: P3980R0
Author: Dietmar Kühl
Date: 2026-02-22
Audience: LEWG

Addresses four NB comments about how std::execution::task uses allocators. The key separation: the allocator for the coroutine frame and the allocator for child sender environments should be handled independently. The frame allocator comes from the task's constructor arguments; the child environment allocator comes from the receiver. Presents three wording approaches (A, B, C) with different levels of strictness on allocator_arg positioning.

▲ 52 points (84% upvoted) · 16 comments
sorted by: best
u/allocator_propagation_veteran 38 points 6 hr. ago

Separating frame allocator from child environment allocator is the right design. The frame allocator controls where the coroutine itself lives. The environment allocator controls what the task's children see. These are different concerns with different lifetimes, and conflating them was the source of three of the four NB comments.

u/p3796_issue_tracker 31 points 6 hr. ago

This is one of the 29 issues from P3796R1. The task type was adopted and then immediately needed rework. The allocator model is particularly tricky because operator new in the coroutine frame runs before the promise constructor - the allocator has to be available before the coroutine body starts.

u/coroutine_timing_expert 18 points 5 hr. ago

The timing problem is exactly what P4003R0 solves with thread-local propagation. Different approach, same underlying constraint: the allocator must be present at invocation time.

u/three_wording_options 24 points 5 hr. ago

Three wording approaches for one NB comment resolution. Option A constrains allocator_arg to first position. Option B allows flexible positioning matching std::generator. Option C is a middle ground. This is LEWG design space exploration - they'll poll and pick one.

u/generator_consistency 17 points 4 hr. ago

Consistency with std::generator's allocator model should be the priority. Both are coroutine types. Both need allocators for frame allocation. Users shouldn't learn two different allocator conventions for two standard coroutine types.

u/four_nb_comments_one_paper 12 points 3 hr. ago

Four NB comments on allocator use for a single type. This is what happens when you ship a design and discover the allocator story wasn't fully baked. Kühl is doing the cleanup work. Necessary, not glamorous.

u/receiver_environment_allocator 9 points 2 hr. ago

Taking the child allocator from the receiver's environment is elegant. The receiver already carries the execution context. Adding the allocator to that context means child tasks automatically inherit the allocation strategy without explicit propagation.

u/task_type_pessimist 6 points 1 hr. ago

Six months after adoption and we're reworking the allocator model. Between this, P3796R1's 29 issues, and P3801R0's design concerns, std::execution::task is getting more post-adoption patches than C++11 std::regex got complaints.