C++ Logo

std-proposals

Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Wed, 29 Nov 2023 13:10:30 +0100
"Abandoning" (however defined) C++ objects without calling the destructor is not something you want to give an easy to call high-level (within std:optional) member function for. Especially from the outside (blackbox) without knowledge or support of those objects. Especially reusing memory, which is still referred to from actively running code (within the also "abandoned", but still running, threads), can lead to all kind of side-effects.   If you do not want to use the heap and discard pointers, you can alternatively allocate an array for your potential thread pool and have pointers to elements of that array. That would be much cleaner and safer and also support the case that threads get alive again even after the timeout.   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mi 29.11.2023 11:28 Betreff:Re: [std-proposals] void std::optional<T>::abandon(void) noexcept An:std-proposals_at_[hidden]; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; On Tue, Nov 28, 2023 at 8:50 PM Thiago Macieira > > > Read: "I have a bug in my software and I want to work around it". > > You should fix the bug instead. Make your thread properly time out and give the > proper notification that it failed, so the future knows so. I think it's either a device driver, or the operating system, or the virtual machine software that's locking up. I've got Linux running in a virtual machine, with the internet connect bridged to the host PC, and inside the virtual machine I have an SSH connection to a remote computer on the internet over which I'm passing TCP traffic. If the SSH connection dies for a few seconds, I get a total lock up of the thread. But of course the details of my project aren't particularly relevant here on this mailing list -- the principle here is that sometimes, although rarely, you want to just give up on an object and forget about destroying it. For now I think I'll just do:    memset( &obj.value(), 0, sizeof obj.value() );    // not needed but paranoia is good    ::new( &obj.value() ) std::future<bool>(); This kind of thing but also be needed for example in embedded systems if a bus manager locks up. -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-11-29 12:10:32