Skip to content

gh-137992: Stop the world when calling PyRefTracer_SetTracer and PyRefTracer_GetTracer #137994

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Aug 20, 2025

return 0;
}

PyRefTracer PyRefTracer_GetTracer(void** data) {
_Py_AssertHoldsTstate();
_PyEval_StopTheWorldAll(&_PyRuntime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the point of stop-the-world is that it functions like an RW lock. Fast, uncontended reads, with a single thread getting exclusive access while writing. Do we write to tracer_data anywhere else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's written by PyRefTracer_SetTracer above

Copy link
Member

@ZeroIntensity ZeroIntensity Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but then we don't need to stop the world for the reader. I was asking about other writers to see if there was a reason the reader had exclusive access.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, I don't think we need a stop-the-world for PyRefTracer_GetTracer. If we did, we'd also need one for _PyReftracerTrack, which is obviously not reasonable.

@@ -3286,16 +3286,20 @@ _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)

int PyRefTracer_SetTracer(PyRefTracer tracer, void *data) {
_Py_AssertHoldsTstate();
_PyEval_StopTheWorldAll(&_PyRuntime);
_PyRuntime.ref_tracer.tracer_func = tracer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will still race with isolated subinterpreters on non-FT builds.

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

Successfully merging this pull request may close these issues.

3 participants