Skip to content

Commit 38c3f11

Browse files
[3.15] gh-149162: Use _Py_LOCK_DONT_DETACH in intern_common (gh-149164) (gh-153814)
Avoids potential deadlocks with C++ static local initialization in extensions that call PyUnicode_InternFromString during one-time initialization. (cherry picked from commit f62050d) Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent 9fcebd3 commit 38c3f11

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a potential deadlock in :c:func:`PyUnicode_InternFromString` and other
2+
interning functions in the :term:`free-threaded build` when called from C++
3+
static local initializers.

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14344,7 +14344,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */,
1434414344
}
1434514345
#endif
1434614346

14347-
FT_MUTEX_LOCK(INTERN_MUTEX);
14347+
FT_MUTEX_LOCK_FLAGS(INTERN_MUTEX, _Py_LOCK_DONT_DETACH);
1434814348
PyObject *t;
1434914349
{
1435014350
int res = PyDict_SetDefaultRef(interned, s, s, &t);

0 commit comments

Comments
 (0)