mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
gh-129732: Fix race on shared->array
in qsbr code under free-threading (gh-129738)
The read of `shared->array` should happen under the lock to avoid a race.
This commit is contained in:
parent
78377c788e
commit
b4ff8b22b3
2 changed files with 7 additions and 6 deletions
|
@ -0,0 +1 @@
|
||||||
|
Fixed a race in ``_Py_qsbr_reserve`` in the free threading build.
|
|
@ -205,15 +205,15 @@ _Py_qsbr_reserve(PyInterpreterState *interp)
|
||||||
}
|
}
|
||||||
_PyEval_StartTheWorld(interp);
|
_PyEval_StartTheWorld(interp);
|
||||||
}
|
}
|
||||||
PyMutex_Unlock(&shared->mutex);
|
|
||||||
|
|
||||||
if (qsbr == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return an index rather than the pointer because the array may be
|
// Return an index rather than the pointer because the array may be
|
||||||
// resized and the pointer invalidated.
|
// resized and the pointer invalidated.
|
||||||
return (struct _qsbr_pad *)qsbr - shared->array;
|
Py_ssize_t index = -1;
|
||||||
|
if (qsbr != NULL) {
|
||||||
|
index = (struct _qsbr_pad *)qsbr - shared->array;
|
||||||
|
}
|
||||||
|
PyMutex_Unlock(&shared->mutex);
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue