Python’s GIL does exactly nothing to prevent data races (or any other concurrency issues); it merely protects the runtime from memory corruption stemming from concurrency.
Obviously, the fundamental issue with concurrency is programmer’s intent. This statement:
x += 1; y -= 1
can be interpreted in two ways:
atomic {
x += 1
y -= 1
}
or
atomic { x += 1 }
atomic { y -= 1 }
The best the compiler can do would be to alert the programmer of the ambiguity; I know of no compiler that does that.
Obviously, the fundamental issue with concurrency is programmer’s intent. This statement:
can be interpreted in two ways: or The best the compiler can do would be to alert the programmer of the ambiguity; I know of no compiler that does that.