Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intrusive_ptr not threadsafe #991

Open
kpu opened this issue May 6, 2023 · 0 comments
Open

intrusive_ptr not threadsafe #991

kpu opened this issue May 6, 2023 · 0 comments

Comments

@kpu
Copy link
Member

kpu commented May 6, 2023

The reference counter is a bare size_t

#define ENABLE_INTRUSIVE_PTR(type) \
size_t references_{0}; \

and the pointer type is a bare pointer:

If two threads destroy their references simultaneously, then both enter this function:

inline friend void intrusivePtrRelease(type* x) { \
if(x != 0 && --x->references_ == 0) { \
delete x; \
x = 0; \
} \
} \

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant