cplusplus / sender-receiver

Issues list for P2300
Apache License 2.0
20 stars 3 forks source link

Define a policy for resuming leaf operations that avoids running continuations inline on context that triggered completion #269

Open lewissbaker opened 4 months ago

lewissbaker commented 4 months ago

There are several data-structures that have async operations where a consumer that waits on something is un-blocked by some other operation on the data-structure.

For example:

These are just two examples of this kind of "something happens that triggers completion of some waiting operation" situation - this situation will recur on almost all data-structures that have a "wait until something happens" async operation.

We need to come up with a strategy/pattern that we can apply to such data-structures to ensure that they have consistent behaviour that doesn't have the inline-completion footguns.

Several options to consider:

Note that this may tie in with the task design - the task coroutine type may implicitly apply such an algorithm to all co_await expressions within the coroutine.

lewissbaker commented 1 week ago

A paper along these lines would also need to consider what to do when that scheduler that completion of the operation is scheduled onto is a fallible scheduler and what to do if it actually fails to schedule onto that context.

lewissbaker commented 1 week ago

@ispeters Mentioned that the async_scope paper already has the suggested behaviour for the join() operation on an async-scope.

lewissbaker commented 1 week ago

One thing I'm not sure about is how to define a policy/design-guideline for subsequent facilities that are proposed to ensure that they all follow this design. e.g. if we add an async_mutex, async_semaphore, or other things with a 'wait' operation.

We could encode this guideline in a paper and then just ensure that SG1 understands this and requests that similar looking things that come past SG1 refer to that paper and apply it to the new facilities. I don't think there's anything actionable for things added by P2300, though.

ispeters commented 1 week ago

@ispeters Mentioned that the async_scope paper already has the suggested behaviour for the join() operation on an async-scope.

Here: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3149r6.html#simple_counting_scopejoin

lewissbaker commented 5 days ago

I think we need to have a paper discussing the potential approaches to completion context for certain kinds of senders and their relative trade-offs.

There is a tension here between minimising overhead (allowing inline completion), separation of concerns (not requiring leaf operations to all have to deal with schedulers) and safety (running continuations on unexpected contexts inside innocent looking calls).

@robertleahy Would like to provide some input on this.