Home > Backend Development > C++ > Does C Provide a Non-Atomic Equivalent of `std::shared_ptr`?

Does C Provide a Non-Atomic Equivalent of `std::shared_ptr`?

Mary-Kate Olsen
Release: 2024-10-27 16:28:01
Original
620 people have browsed it

Does C   Provide a Non-Atomic Equivalent of `std::shared_ptr`?

No Atomic Version of std::shared_ptr

Question: Does a non-atomic equivalent of std::shared_ptr exist outside the standard library? Why was a non-atomic version not included in C 11?

Answer:

1. Non-Atomic Equivalent

std::shared_ptr, unlike other smart pointers in the standard library, is atomic. While there may be third-party alternatives, the standard itself does not provide a non-atomic version.

2. Exclusion from C 11

The inclusion of a non-atomic std::shared_ptr was debated at the C 11 Rapperswil meeting. Arguments against its inclusion included:

  • Potential for code using the non-atomic version to be later used in threaded code, leading to undetected issues.
  • The benefits of having a "universal" shared_ptr, regardless of features used.
  • The minimal performance impact of atomicity, mitigated by move construction and assignment.
  • The ability for users to implement their own non-atomic reference-counted smart pointers if needed.

After consideration, the LWG ultimately rejected the proposal for a non-atomic std::shared_ptr, reasoning that it lacked clear consensus and the benefits did not outweigh the drawbacks.

The above is the detailed content of Does C Provide a Non-Atomic Equivalent of `std::shared_ptr`?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template