Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ebd0a95
Thread-safety prep for free-threading builds
greateggsgreg May 9, 2026
cf8372a
Initialise pythonnet on free-threaded Python (#2720)
greateggsgreg May 9, 2026
441954f
Make extension/CLR-object registries thread-safe
greateggsgreg May 9, 2026
19c7f59
Atomic type creation in ReflectedClrType.GetOrCreate / TypeManager.Ge…
greateggsgreg May 9, 2026
1029c62
Add free-threaded thread-stress tests and 3.14t to CI matrix
greateggsgreg May 9, 2026
3158ca5
Atomic GCHandle ownership and finalizer-thread shutdown guards
greateggsgreg May 10, 2026
1149295
Make additional internal registries thread-safe
greateggsgreg May 10, 2026
e8afa85
test_thread: join worker threads before returning
greateggsgreg May 10, 2026
3954df3
test_thread: cover ModuleObject thread-safe registries
greateggsgreg May 10, 2026
28013af
Wider thread-safety audit fixes for free-threaded Python
greateggsgreg May 10, 2026
9a3dd59
Document lock acquisition sites and strong->weak GCHandle swap
greateggsgreg May 10, 2026
cb1dcde
Preserve InternString single-write invariant under DEBUG
greateggsgreg May 10, 2026
74d12f1
test_thread: cover real-world consumer patterns
greateggsgreg May 10, 2026
a30c84e
Auto-detect free-threaded libpython in venv home
greateggsgreg May 12, 2026
be5ba34
Snapshot pypath, use ConcurrentDictionary for thunks and slot holders
greateggsgreg May 13, 2026
946785e
Fix handling of python runtime suffixes m/t
greateggsgreg May 13, 2026
77ca497
Fix threadtest race
greateggsgreg May 13, 2026
af518bb
Fix double-free in chained ClassDerived Finalize
greateggsgreg May 13, 2026
ed735ac
Enable Mono CI jobs on free-threaded Python 3.14
greateggsgreg May 13, 2026
bd3f0bf
Inline freethreaded_only as pytest.mark.skipif at call sites
greateggsgreg May 13, 2026
c4688b3
Fix InterruptTest assertion on free-threaded Python 3.14
greateggsgreg May 13, 2026
84cd07c
Add concurrent stress tests for PyBuffer.Dispose and CLR-cycle gc.col…
greateggsgreg May 15, 2026
d9b658d
Trim concurrent overhead on hot paths from free-threading prep
greateggsgreg May 15, 2026
20c51ad
Pre-warm ctor binder in concurrent-gc test to avoid first-call race
greateggsgreg May 15, 2026
f5f8ab0
Make MethodBinder.GetMethods lazy init thread-safe under free-threading
greateggsgreg May 15, 2026
c5097eb
Precompute method precedence to avoid quadratic GetParameters allocat…
greateggsgreg May 15, 2026
18e4901
Zero the slot in ClassDerived.tp_dealloc when tp_clear already ran to…
greateggsgreg May 15, 2026
e0569d0
Keep ClassDerived wrapper alive across the NewObjectToPython slot dem…
greateggsgreg May 15, 2026
2c9f861
Document private helpers added during free-threading prep
greateggsgreg May 16, 2026
ee3add4
Add debug echoes and a 6-minute step timeout to the Mono test job
greateggsgreg May 16, 2026
414ce70
Drop the per-loop CLR GC.Collect from concurrent-gc test to avoid Mon…
greateggsgreg May 16, 2026
99a99db
Add temporary Mono-step diagnostics on Linux/macOS to locate the x64-…
greateggsgreg May 16, 2026
8e7c2ba
Revert temporary Mono-step diagnostics now that the underlying race i…
greateggsgreg May 16, 2026
f8b69a2
Merge branch 'master' into freethreading-prep
greateggsgreg May 16, 2026
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
Prev Previous commit
Next Next commit
Document private helpers added during free-threading prep
  • Loading branch information
greateggsgreg committed May 16, 2026
commit 2c9f861ed2be795a57a861b356a63b44f1c1aae6
4 changes: 4 additions & 0 deletions src/runtime/DelegateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ private Type GetDispatcher(Type dtype)
}
}

/// <summary>
/// Emits a new <see cref="Dispatcher"/> subclass for <paramref name="dtype"/>
/// and caches it. Must be called under <c>_emitLock</c>.
/// </summary>
private Type BuildDispatcher(Type dtype)
{
string name = $"__{dtype.FullName}Dispatcher";
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/MethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ internal MethodBase[] GetMethods()
}
}

/// <summary>
/// Sort key for <see cref="GetMethods"/>: derived-class methods come before
/// their base, otherwise by precomputed precedence (lower wins).
/// </summary>
private static int CompareByDeclaringTypeThenPrecedence(
KeyValuePair<MethodBase, int> a, KeyValuePair<MethodBase, int> b)
{
Expand Down
7 changes: 7 additions & 0 deletions src/runtime/Native/ABI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ internal static void Initialize(Version version)
TypeOffset.Use(typeOffsets, nativeOffsetsClass == null ? ObjectHeadOffset : 0);
}

/// <summary>
/// True when the running interpreter is a Py_GIL_DISABLED (free-threaded) build.
/// </summary>
static bool DetectFreeThreaded()
{
// sys._is_gil_enabled() was added in Python 3.13; absent means GIL build.
Expand All @@ -56,6 +59,10 @@ static bool DetectFreeThreaded()
return Runtime.PyObject_IsTrue(result.Borrow()) == 0;
}

/// <summary>
/// Locates the offset of <c>ob_refcnt</c> inside <c>PyObject</c> by allocating a
/// fresh list and scanning for its refcount value of 1. GIL builds only.
/// </summary>
static unsafe int ProbeRefCountOffset()
{
using var tempObject = Runtime.PyList_New(0);
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/PythonTypes/PyBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public void Read(byte[] buffer, int destinationOffset, int count, nint sourceOff
// 0/1; atomic so finalizer + Dispose cannot double-free the buffer.
private int disposedValue;

/// <summary>
/// Throws <see cref="ObjectDisposedException"/> if <see cref="Dispose()"/> has
/// already released the buffer view.
/// </summary>
private void ThrowIfDisposed()
{
if (Volatile.Read(ref disposedValue) != 0)
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/Types/ClassDerived.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ internal static Type CreateDerivedType(string name,
}
}

/// <summary>
/// Emits the CLR type for a Python subclass. Must be called under
/// <c>_buildersLock</c> since Reflection.Emit is not thread-safe.
/// </summary>
private static Type CreateDerivedTypeImpl(string name,
Type baseType,
IList<Type> typeInterfaces,
Expand Down
Loading