|
|
|
|
|
by Znafon
1038 days ago
|
|
Yes this is a thing was trivially protected by the GIL. There is the same thing with mutating the same map concurrently in Go that will panic for example. PEP 703 goes over this in the "Container Thread-Safety" (I think container here refers to the fact that the object has references to other objects, this is the things that already are special-cased in CPython to be managed specifically by the garbage collector): > This PEP proposes using per-object locks to provide many of the same protections that the GIL provides. For example, every list, dictionary, and set will have an associated lightweight lock. All operations that modify the object must hold the object’s lock. Most operations that read from the object should acquire the object’s lock as well; the few read operations that can proceed without holding a lock are described below. More information at https://peps.python.org/pep-0703/#container-thread-safety |
|
For example, Java implements different versions of containers for single thread and multithread usage, because multithreaded containers have obvious performance penalty
https://docs.oracle.com/javase/8/docs/api/java/util/concurre...