I have thread A that allocates memory and assigns it to a shared pointer. Then this thread generates 3 other threads X, Y and Z and passes a copy of the common pointer to each. When X, Y and Z go beyond, memory is freed. But is there a chance that 2 threads X, Y will leave the scope at the same time, and there is a race condition on the link counter, instead of decrementing it by 2, it only decreases once. So, now the reference count is reduced to 0, so a memory leak occurs. Note that X, Y, and Z only read memory. Do not write or restore the shared pointer. In short, could there be a race condition on the link counter and could this lead to memory leaks?
c ++ multithreading boost shared-ptr
Nikhil
source share