What thread safe code can I write with the GIL that will have a race without it?
I already have to be careful to only write to a shared object from one thread, since I have no guarantees on order of execution.
The main benefit of the GIL, from my recent reading is that it makes ref counting fast and thread safe. The meat of the proposal is changing ref counting so that it's almost as fast and atomic without the GIL.
What about setting a simple boolean flag, e.g. setting "cancelled = True" in the UI thread to cancel an operation in a background thread?
In Java you would have to worry about safe publication to make the change visible to the other thread, but thanks to the GIL changes in Python are always (I think?) made visible to other threads.
changes are always eventually made visible to other threads in all modern languages - it's the timing of thread wakeup and the possibility that the thread may not flush a cache that is uncertain. the GIL doesn't magically solve race conditions, and in Java and other such languages, you usually have a keyword like volatile that can make flushes explicit. In any case, I very much doubt the GIL work would affect Python's cache coherency model.
I already have to be careful to only write to a shared object from one thread, since I have no guarantees on order of execution.
The main benefit of the GIL, from my recent reading is that it makes ref counting fast and thread safe. The meat of the proposal is changing ref counting so that it's almost as fast and atomic without the GIL.