6 ms·
"Thanks to GIL, multithreading in CPython is just broken and doesn't work." Fixed that for you.
by BerislavLopac 6y ago
"Thanks to GIL, multithreading in CPython is just broken and doesn't work."
Fixed that for you.
- rbanffy 6y ago"Thanks to GIL, multithreading in CPython is just broken and doesn't work." Thanks to the GIL, multithreaded Python code doesn't have to worry too much (you do, a little) about shared mutable objects.
- readmodifywrite 6y agoThe GIL is not there to prevent data corruption on shared objects - it only protects the interpreter's internal state. The fact that sometimes you can get away with it is an accident of the GIL's implementation, not a feature anyone should rely on. It also means that you cannot rely on that behavior not to change on a successive versions of CPython. The only safe way to do shared state between threads in CPython is locks/mutexes/message passing/etc. Even things like a simple addition to an integer are absolutely not made thread safe by the GIL.
- rbanffy 6y agoNo, but at least you won't have two cores incrementing the same integer at the same time.