gh-112075: Free-threaded dict odict basics - #114778
Conversation
77e5821 to
7efcb0f
Compare
7efcb0f to
355a6ce
Compare
colesbury
left a comment
There was a problem hiding this comment.
Some comments below, mostly about formatting.
I'd prefer we focus the thread-safety changes on dict and not OrderedDict for now. OrderedDict is both a bit of a mess in general and harder to do locking in a way that doesn't lead to re-acquiring the lock for the same object.
This will help make it easier to assert in the dictionary API that we have the proper locking in place
I'm a bit skeptical about these sorts of asserts in dict (or list). I expect there to be at least a few places internally where we want to call the unlocked APIs because we know it's safe for other reasons.
For example, the LRU caches uses _PyDict_SetItem_KnownHash, but we will want to do the locking on the lru_cache_object and not the internal dict, and can use the unlocked ("lock_held") variant.
There was a problem hiding this comment.
extern int for consistency with other non-exported functions in this header
|
|
||
|
|
||
| /*[clinic input] | ||
| @critical_section |
There was a problem hiding this comment.
This looks like it will call functions that themselves re-acquire the critical section.

This adds some basic locking to the ordered dict implementation. Nothing fancy, we just take some critical sections and expose
_PyDict_SetItem_KnownHash_LockHeldinternally. This will help make it easier to assert in the dictionary API that we have the proper locking in place.dictobjects thread-safe in--disable-gilbuilds #112075