Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


here's a python code that would break even with GIL:

current_boolean_value = global_cancelled

global_cancelled = new_boolean_value(current_boolean_value)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: