The Non-Atomic Equivalent of std::shared_ptr
Question:
Is there an alternative to std::shared_ptr that lacks its inherent atomicity? Moreover, why does the C Standard Library not include a non-atomic option?
Answer:
1. Availability of Non-Atomic Alternatives:
The C Standard Library does not offer a non-atomic variant of std::shared_ptr. However, third-party libraries may provide such implementations. Prior to the introduction of std::shared_ptr in C 11, many developers created their own reference-counted smart pointers, potentially offering non-atomic options.
2. Rationale for Atomic std::shared_ptr in C 11:
During the C 11 standardization process, the proposal to include a non-atomic version of std::shared_ptr was considered and ultimately rejected. The following arguments influenced this decision:
Proposed Non-Atomic Version:
Despite the rejection in C 11, there may have been proposals for a non-atomic version of std::shared_ptr submitted to Boost or the standards committee. However, these proposals did not gain sufficient support for inclusion in the official standard.
The above is the detailed content of Why Doesn\'t C \'s Standard Library Offer a Non-Atomic Version of `std::shared_ptr`?. For more information, please follow other related articles on the PHP Chinese website!