-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Closed
Labels
Description
Feature or enhancement
The refleak checking relies on per-interpreter "total" refcount tracking. It uses non-atomic operations and is not thread-safe without the GIL.
In the free-threaded build, I think we should primarily track counts in PyThreadState and occasionally aggregate the results into the per-interpreter total refcount using atomic operations.
See:
Lines 72 to 91 in 9dae05e
| # define REFTOTAL(interp) \ | |
| interp->object_state.reftotal | |
| static inline void | |
| reftotal_increment(PyInterpreterState *interp) | |
| { | |
| REFTOTAL(interp)++; | |
| } | |
| static inline void | |
| reftotal_decrement(PyInterpreterState *interp) | |
| { | |
| REFTOTAL(interp)--; | |
| } | |
| static inline void | |
| reftotal_add(PyInterpreterState *interp, Py_ssize_t n) | |
| { | |
| REFTOTAL(interp) += n; | |
| } |
There is also the legacy _Py_RefTotal, but that's just preserved for ABI compatibility. I don't think we have to do anything with that.