Atomic shared pointer Helllo, I am multithreading large piece of code (gcc 7.4, c++17) and I stumbled upon a lot of race conditions when accessing std::shared_ptr. I tried using boost::atomic_shared_ptr, but there are some critical parts of the code where shared pointers are returned from functions, or shared pointers are used in constructors of other classes, which is not supported from boost::atomic_shared_ptr (copy constructor and assignment operator are private). I had 3 other suggestions: -to wrap every place where shared pointer is accessed with mutex, but this looks like overkill to me. -to create my implementation of atomic_shared_pointer. -to use std::atomic_store/std::atomic_load. What is the best way to make the access to the shared pointers thread-safe? Is there something special to consider when returning shared pointer from function, related to atomicity? https://ift.tt/eA8V8J
Helllo, I am multithreading large piece of code (gcc 7.4, c++17) and I stumbled upon a lot of race conditions when accessing std::shared_ptr. I tried using boost::atomic_shared_ptr, but there are some critical parts of the code where shared pointers are returned from functions, or shared pointers are used in constructors of other classes, which is not supported from boost::atomic_shared_ptr (copy constructor and assignment operator are private). I had 3 other suggestions: -to wrap every place where shared pointer is accessed with mutex, but this looks like overkill to me. -to create my implementation of atomic_shared_pointer. -to use std::atomic_store/std::atomic_load. What is the best way to make the access to the shared pointers thread-safe? Is there something special to consider when returning shared pointer from function, related to atomicity?
from GameDev.net https://ift.tt/2G7Gb5R
from GameDev.net https://ift.tt/2G7Gb5R
ليست هناك تعليقات