Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Include/internal/pycore_critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ extern "C" {
// Asserts that the mutex for the given object is locked. The mutex must
// be held by the top-most critical section otherwise there's the
// possibility that the mutex would be swalled out in some code paths.
//
// NOTE: We use Py_REFCNT(op) != 1 instead of
// !PyUnstable_Object_IsUniquelyReferenced(op) because the free threading
// GC can change an object's ob_tid (it overwrites ob_tid and later
// restores it from the mimalloc segment). This means
// PyUnstable_Object_IsUniquelyReferenced() may spuriously return false
// after a GC collection, even though the thread may still have exclusive
// access to the object. The refcount check is a looser but still catches
// most misuses.
#ifdef Py_DEBUG

# define _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op) \
Expand Down
6 changes: 5 additions & 1 deletion InternalDocs/garbage_collector.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ pointer-sized (that is, eight bytes on a 64-bit platform).

The garbage collector also temporarily repurposes the `ob_tid` (thread ID)
and `ob_ref_local` (local reference count) fields for other purposes during
collections.
collections. The `ob_tid` field is later restored from the containing
mimalloc segment data structure. In some cases, such as when the original
allocating thread exits, this can result in a different `ob_tid` value.
Code should not rely on `ob_tid` being stable across operations that may
trigger garbage collection.


C APIs
Expand Down
4 changes: 0 additions & 4 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,10 +1126,6 @@ func_dealloc(PyObject *self)
if (_PyObject_ResurrectEnd(self)) {
return;
}
#if _Py_TIER2
_Py_Executors_InvalidateDependency(_PyInterpreterState_GET(), self, 1);
_PyJit_Tracer_InvalidateDependency(_PyThreadState_GET(), self);
#endif
_PyObject_GC_UNTRACK(op);
FT_CLEAR_WEAKREFS(self, op->func_weakreflist);
(void)func_clear((PyObject*)op);
Expand Down
Loading