C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A non-owning but self zeroing smart pointer for single ownership

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Sat, 22 Feb 2025 08:59:04 +0100
> On Feb 20, 2025, at 10:49 PM, JOHN MORRISON via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> 
> Ok, there is a real thread safety issue, it is serious and I have been working on it.

I think you have some interesting thoughts here. Maybe ptr_to_unique could get a template parameter that defaults to multithreaded use (which will have additional memory overhead), but with an explicit template parameter it can be made single threaded (for memory efficiency and performance reasons). Since the template parameter would be explicit it reduces wrong usage.

I am not sure if throwing an exception when accessing ptr_to_unique is the right choice. Since you should check if the pointer is nullptr before using it ptr_to_unique could always return a nullptr/check equal to nullptr in other threads. No throwing necessary. However, any sort of check for the current thread slows down ALL access to the pointer—even legitimate access.

Received on 2025-02-22 07:59:20