by blibble · 3y ago · 0 comments
not sure there's much they can do about this, other than protecting all the built-in data structure operations with mutexes, like java's original data structures (Hashtable, Vector, etc)
(but then how do you get a non-synchronized [] if you want one?)
> (but then how do you get a non-synchronized [] if you want one?)
You don't. This is one of the reasons why using the GIL is higher performance for single-threaded use-cases: stuff like lists and dicts can be non-synchronized
However - this is fundamentally the incorrect approach, because Vector and Hashtable aren't protected from read-then-write race conditions.
Such internal locking guarantees that the collection stays structurally sound, but not that code accessing it is dealing with a single consistent state until it finishes.
Maybe it could be part of a non_threadsafe_containers module on Pypi.
I'd assume that importing any sort of module level variable would imply an increment of the counter, but unsure.
(admittedly it's python so it's so slow it's probably not even measurable)