C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Coroutine local destructor
From: Marcin Jaczewski (marcinjaczewski86_at_[hidden])
Date: 2020-05-22 13:27:42


pt., 22 maj 2020 o 20:16 Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]> napisał(a):
>
> 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 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"?
>
> –Arthur

Yes, C++20 "destroying destructor" was another possible option to have
this behavior but as I mentioned in first email, it is too forbidden
in this context as only available are:
>
> But destructor can only have two forms:
> ```
> void operator delete(void* p, std::size_t s);
> void operator delete(void* p);
> ```

Another question is what exactly type we will deleting there? Because
`task_promise` is not type that is allocated by `new`, AFAIK promise
is embedded in object that have whole corutine state and we delete
that.


STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups