From 6a64489ccde26d323f35e8d3697db71eeee69eff Mon Sep 17 00:00:00 2001 From: Yue Du Date: Wed, 12 Aug 2026 07:22:15 +0000 Subject: [PATCH 1/2] Unify lock allocation and GIL release thresholds XXHASH_LOCK_MAYBE_INIT allocated the lock at >= XXHASH_GIL_MINSIZE while every GIL release check uses >, so an update of exactly 64KB allocated a lock that was never used. Align both at > XXHASH_GIL_MINSIZE and update the README wording. --- README.rst | 4 ++-- src/_xxhash.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 39b7d42..6a61900 100644 --- a/README.rst +++ b/README.rst @@ -264,8 +264,8 @@ One-shot functions (``xxh32_digest``, ``xxh64_hexdigest``, ``xxh3_128_digest``, etc.) are stateless and always safe to call concurrently. On Python 3.13+ the lock is always active. On Python 3.9-3.12 the lock is -created on the first ``update()`` of 64KB or more; smaller operations never -release the GIL, so they are serialized by the GIL itself. +created on the first ``update()`` of more than 64KB; operations of 64KB or +less never release the GIL, so they are serialized by the GIL itself. Sharing a streaming hash object across threads is still discouraged: even with locking, the order in which concurrent updates are applied (and hence diff --git a/src/_xxhash.c b/src/_xxhash.c index 01c3716..6bffdf6 100644 --- a/src/_xxhash.c +++ b/src/_xxhash.c @@ -47,10 +47,10 @@ # define XXHASH_LOCK_FIELD PyThread_type_lock lock; # define XXHASH_LOCK_INIT(o) ((o)->lock = NULL) # define XXHASH_LOCK_IS_ACTIVE(o) ((o)->lock != NULL) -/* Lazy allocation on first large update */ +/* Lazy allocation on first update large enough to release the GIL */ # define XXHASH_LOCK_MAYBE_INIT(o, len) \ do { \ - if ((o)->lock == NULL && (len) >= XXHASH_GIL_MINSIZE) { \ + if ((o)->lock == NULL && (len) > XXHASH_GIL_MINSIZE) { \ (o)->lock = PyThread_allocate_lock(); \ /* fail? lock stays NULL, fall back to non-threaded code. */ \ } \ From f0b2b5bbfd3ab9ca7344158fc3c30f5dadcf3f7d Mon Sep 17 00:00:00 2001 From: Yue Du Date: Wed, 12 Aug 2026 07:59:59 +0000 Subject: [PATCH 2/2] Bump version to 4.0.0.dev8 --- xxhash/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xxhash/version.py b/xxhash/version.py index d145710..fb5693b 100644 --- a/xxhash/version.py +++ b/xxhash/version.py @@ -1 +1 @@ -VERSION = "4.0.0.dev7" +VERSION = "4.0.0.dev8"