intrusive_ptr not threadsafe
kpu opened this issue · 0 comments
kpu commented
The reference counter is a bare size_t
marian-dev/src/common/intrusive_ptr.h
Lines 15 to 16 in 3daf4ee
and the pointer type is a bare pointer:
marian-dev/src/common/intrusive_ptr.h
Line 137 in 3daf4ee
If two threads destroy their references simultaneously, then both enter this function:
marian-dev/src/common/intrusive_ptr.h
Lines 23 to 28 in 3daf4ee
It's possible both threads will read
x != 0
and x->references_ == 2
then commit 1 back and leak the object.
Aside: this line doesn't do anything since it's in a function that takes type* x
marian-dev/src/common/intrusive_ptr.h
Line 26 in 3daf4ee