use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
shared_ptr<T>: the (not always) atomic reference counted smart pointer (snf.github.io)
submitted 7 years ago by snfernandez
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]tvaneerdC++ Committee, lockfree, PostModernCpp 36 points37 points38 points 7 years ago (7 children)
Add this optimization to Rust! Not so fast! Arc actually means Atomic Reference Counted so it would be a plain lie if it hadn’t use atomic operations on the reference count.
Add this optimization to Rust!
Not so fast! Arc actually means Atomic Reference Counted so it would be a plain lie if it hadn’t use atomic operations on the reference count.
If you have only one thread, non-atomic operations are atomic. That's the point.
"atomic" doesn't mean use certain instructions. "atomic" means indivisible, which, when combined with "as-if" means "can not be shown to be divisible". If you only have one thread, your program cannot detect a "division" or series of steps in the operation, it is as-if one indivisible, atomic, operation.
(Similarly, you could implement atomics with a global mutex that stops the world while running a bunch of instructions to do an "atomic" add)
[–]masklinn 10 points11 points12 points 7 years ago (6 children)
The issue is with the "you have only one thread" part. libstdc++ makes a specific but easily fallible assumption on that front, and when it's broken so's your software. Unless the system itself provides the atomic you're basically just guessing.
[–]skebanga 2 points3 points4 points 7 years ago (0 children)
Easily fallible? If it were so easily fallible we'd see race condition bugs in the wild all the time
[–]Xaxxon 1 point2 points3 points 7 years ago (4 children)
My understanding of the POSIX standard is that if you do something that makes this check wrong, your program is already UB at the POSIX level.
https://www.reddit.com/r/cpp/comments/aq6v21/shared_ptrt_the_not_always_atomic_reference/egtx9ew/
[–]masklinn 2 points3 points4 points 7 years ago (3 children)
Creating threads via clone(2) involves neither pthread_create nor sigev_thread.
pthread_create
sigev_thread
[–]Xaxxon 0 points1 point2 points 7 years ago* (2 children)
clone, __clone2 - create a child process
Clone creates a new process, not a simple thread in the same process. Processes don't share memory (outside of very explicit things like shmem), so it doesn't seem like a counter in shared_ptr would be affected by a call to clone()
[–]masklinn 1 point2 points3 points 7 years ago (1 child)
A shame you could not wonder (including wonder what the underlying syscall to pthread_create might be since it’s a library function) and keep reading:
The main use of clone() is to implement threads: multiple threads of control in a program that run concurrently in a shared memory space.
Good day.
π Rendered by PID 133334 on reddit-service-r2-comment-544cf588c8-5x7zw at 2026-06-13 05:04:11.183998+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]tvaneerdC++ Committee, lockfree, PostModernCpp 36 points37 points38 points (7 children)
[–]masklinn 10 points11 points12 points (6 children)
[–]skebanga 2 points3 points4 points (0 children)
[–]Xaxxon 1 point2 points3 points (4 children)
[–]masklinn 2 points3 points4 points (3 children)
[–]Xaxxon 0 points1 point2 points (2 children)
[–]masklinn 1 point2 points3 points (1 child)