2 ms·
For example, in CPython multiple threads can append to a list without a lock or insert items into a dict without a lock, and the data structure will never becom
by formerly_proven 5y ago
For example, in CPython multiple threads can append to a list without a lock or insert items into a dict without a lock, and the data structure will never become corrupted. If you do the same thing in Java with an ArrayList, there's a chance that some items are lost.
Though it is worth pointing out that Java has a well-defined memory model, and Python doesn't. So the above is true for CPython, but it might not work in other implementations, or, for example, you might have a library providing data structures, and it might not hold for those, either.
- needusername 5y ago> For example, in CPython multiple threads can append to a list without a lock or insert items into a dict without a lock, and the data structure will never become corrupted. How is this achieved? > Though it is worth pointing out that Java has a well-defined memory model, and Python doesn't. Wouldn't you have to at least issue an mfence when a thread enters / exists the GIL?