@@ -80,14 +80,19 @@ will automatically download it.
80
80
This wrapper is not currently thread-safe. Like the hash implementations
81
81
in the Python standard library, we release the GIL during ` update ` , to
82
82
avoid blocking the entire process. However, that means that calling the
83
- ` update ` method from multiple threads at the same time is undefined
84
- behavior. We could solve this by putting a ` Mutex ` inside the wrapper
85
- type, but I'd like to get some expert advice about the best practice
86
- here first.
83
+ ` update ` method on the same object from multiple threads at the same
84
+ time is undefined behavior. We could solve this by putting a ` Mutex `
85
+ inside the wrapper type, but I'd like to get some expert advice about
86
+ the best practice here first.
87
87
88
88
A deeper problem is that another thread might mutate a ` bytearray ` while
89
89
we're hashing it, and while our Rust code is treating it as a ` &[u8] ` .
90
90
That violates Rust's aliasing guarantees and is also technically
91
91
undefined behavior. However, the only possible way to solve this while
92
92
still supporting ` bytearray ` would be to retain the GIL. Again, I'm in
93
93
need of expert advice.
94
+
95
+ These concerns are more theoretical than practical, however. If you're
96
+ racing to update a hasher, or racing to hash a buffer while it's being
97
+ written to, the result is inherently nondeterministic. That's almost
98
+ certainly a bug in your program, whether or not it's technically sound.
0 commit comments