C++ Logo

std-proposals

Advanced search

Re: [std-proposals] void std::optional<T>::abandon(void) noexcept

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Tue, 28 Nov 2023 17:37:52 +0300
On 11/28/23 16:22, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Tue, Nov 28, 2023 at 1:16 PM Andrey Semashev wrote:
>>
>> This would result in UB or resource leak.
>
> When you program in the real world, stuff like this is sometimes
> necessary. If you have spawned 6 threads, and if one of them freezes,
> you can abandon the frozen thread and just start another one. I would
> however keep count of how many threads have been frozen so far, and
> when it reaches 12, tell the user that it's time to restart the
> program. The user will probably be done using the program before it
> climbs to 12.

When your thread unexpectedly blocks for unknown duration, your proposed
abandon() method is not the solution. Not in a "real world" program,
anyway. (In your toy project that noone will ever use you can do
whatever, but that doesn't necessitate changing the standard.)

Received on 2023-11-28 14:37:55