C++ Logo


Advanced search

Re: Coroutine local destructor

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 22 May 2020 14:16:20 -0400
On Fri, May 22, 2020 at 1:52 PM Marcin Jaczewski <
marcinjaczewski86_at_[hidden]> wrote:

> This is what I try to achieve:
> https://gcc.godbolt.org/z/hhiBYZ
> Idea is have stackfull corutine with local memory allocation. Idea is
> that you can have multiple corutines start in one function and each
> have its own buffer.
> [...]
> There is no easy way to have this `LocalStack&` for `delete`.
> Right now only way I see is add special code to `task<>` destructor
> and pass information other way to correctly release memory.

It does surprise me that both
`PromiseType::get_return_object_on_allocation_failure()` and
`PromiseType::operator delete` were specified to take zero arguments,
instead of taking the same "parameter preview" arguments as `operator
new`. That seems like a mistake by WG21. Allocation and deallocation are
flip sides of the same coin; of course they require the same parameters to
accomplish their job.
Mathias Stearn (cc'ed) authoritatively comments here
<https://hackmd.io/_at_[hidden]/S1H_loeA7?type=view> that parameter
preview isn't supported in these cases, but I don't know why not.

If your goal is just to permit the deallocation function to access
`LocalStack& ls`, could you store a pointer to `ls` inside the `Promise`
itself, and then give it a C++20 "destroying destructor"?


Received on 2020-05-22 13:19:35