Skip to content

Commit e960610

Browse files
committed
Discourage concurrent update/reset even with xxhash.threadsafe
1 parent 9322cf5 commit e960610

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,18 @@ external synchronization.
263263
One-shot functions (``xxh32_digest``, ``xxh64_hexdigest``, ``xxh3_128_digest``,
264264
etc.) are stateless and always safe to call concurrently.
265265

266-
If you need to share a streaming hash object across threads, use the
266+
Concurrent ``update()`` / ``reset()`` on a shared streaming hash object is
267+
discouraged even with locking — prefer one-shot functions or per-thread hash
268+
objects. If you must share a streaming hash across threads, use the
267269
``xxhash.threadsafe`` submodule. It provides the same API with a per-object
268-
lock that protects all access to the internal xxHash state:
270+
lock that serializes all access to the internal xxHash state:
269271

270272
.. code-block:: python
271273
272274
>>> from xxhash import threadsafe
273275
>>> h = threadsafe.xxh64()
274-
>>> # h can now be safely updated from multiple threads
276+
>>> # h can be updated from multiple threads, but concurrent update/reset
277+
>>> # still adds overhead and is not recommended
275278
276279
The same two-module split is provided on free-threading (no-GIL) Python
277280
builds: the default module is unlocked, and ``xxhash.threadsafe`` provides a

0 commit comments

Comments
 (0)