4 ms·
> Reference counted pointers themselves are usually not atomic, only the reference count updates are. Fun way to start an argument where everybody is wrong: as
by pdpi 4y ago
> Reference counted pointers themselves are usually not atomic, only the reference count updates are.
Fun way to start an argument where everybody is wrong: ask a group of C++ programmers whether std::shared_ptr is thread-safe.
- TillE 4y agoshared_ptr's thread safety is simple: it's perfectly thread-safe as long as each thread has its own copy. It of course does not provide any synchronization for the object it's pointing to.
- kccqzy 4y agoAlmost exactly one month ago I have a junior developer share the same shared_ptr across threads, where some threads could be writing to it by calling reset(). They forget that accessing the shared_ptr itself needs to be protected. Rust prevents this problem completely though. You are either going to deal with Arc<Mutex<T>> or Mutex<Arc<T>>, depending on the situation (in this case the latter), and forgetting the Mutex will simply cause compilation failure.
- maxbond 4y agoRelated talk from cppcon: https://youtu.be/lkgszkPnV8g https://youtu.be/lkgszkPnV8g