Modify

Opened 4 years ago

#8599 new Feature Requests

enable_shared_from_this -- no throw alternative

Reported by: ingo.loehken@… Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.52.0 Severity: Problem
Keywords: enable_shared_from_this, no throw, weak_this Cc:

Description

I think that enable_shared_from_this misses one feature, that is accessible for weak_ptr and allows no throw access to the underlying instance to a shared_ptr, by either a valid pointer or a null_ptr (boost::weak_ptr::lock).

It would be great to have such a mechanism for enable_shared_from_this as well -- i.e. returning the weak_ptr via member functions weak_this and then chain with lock -- to avoid bad_weak_ptr exception.

Background: Combining intrusive container with enable_shared_from_this and auto-unlink option, where the element own the container, the only way to determine if an element is currently unlinking itself in muti threaded execution, is via an exception, rather than just checking for a null_ptr.

Where this setup might sound very rare, it is one of the most powerful combinations of shared_ptr aliasing, intrusive-containers and enable_shared_from_this for perfect concurrent lookup containers.

And under multi-threading conditions, the exception may get very common and therefore expensive.

Attachments (0)

Change History (0)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Peter Dimov.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.