Opened 9 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.

Change History (0)

Note: See TracTickets for help on using tickets.