Make hashlib related modules thread-safe without the GIL #111916
Closed
Labels
3.13
bugs and security fixes
extension-modules
C modules in the Modules dir
topic-free-threading
type-feature
A feature request or enhancement
Feature or enhancement
The hashlib based modules already have some locking to make some operations thread-safe (with the GIL), but the logic isn't sufficient if running with the GIL disabled.
Relevant files:
Basic idea:
PyThread_type_lock lock
withPyMutex
. This should be both simpler and faster in general and avoid the need for dynamically assigning a lock, which can pose thread-safety issues without the GILbool use_mutex
to indicate if the code should lock the mutex. This should always be set totrue
inPy_NOGIL
. In the default build, we should dynamically set it totrue
in places where we previously allocatedself->lock
ENTER_HASHLIB
andEXIT_HASHLIB
macros.Linked PRs
The text was updated successfully, but these errors were encountered: