C++ Logo

std-proposals

Advanced search

Re: async coroutines vs. lambdas

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Thu, 14 May 2020 16:06:13 +0200
czw., 14 maj 2020 o 15:55 Ville Voutilainen
<ville.voutilainen_at_[hidden]> napisaƂ(a):
>
> On Thu, 14 May 2020 at 16:53, Ville Voutilainen
> <ville.voutilainen_at_[hidden]> wrote:
> >
> > On Thu, 14 May 2020 at 16:31, Marcin Jaczewski via Std-Proposals
> > <std-proposals_at_[hidden]> wrote:
> > > And code like:
> > >
> > > ```
> > > lazy<int> get_custom_lambda() {
> > > struct X
> > > {
> > > int i = 3;
> > > lazy<int> operator()(){ co_return i; }
> > > } x();
> > > return x();
> > > }
> > >
> > > ```
> > >
> > > This still crash, and this is same code as `get_real_lambda`.
> > > How do you like fix it? and what if lambda is not movable?
> >
> > If I swap those co_return/return, will this code then work?
>
> And follow-up question, what if they're both co_returns?

If we change last `return` to `co_returns` then object `x` will be
embedded in `get_custom_lambda` context.
Operator if `operator()()` is normal function then it should always
work. if is corutnie then it will break only if inner one could
outlive outer one. This depend on `lazy` destructor, if he cancel
request then everything would work fine. In case if it not cancel
inner corutine then we could still have UB becasue both corunite
context could be allocated in same block of memory with
`get_custom_lambda` (or this is forbidden in case like this?).

Received on 2020-05-14 09:09:26