Remove handler callbacks before setting disposed.#425
Conversation
This change ensures that you can never observe `disposed` being set to `true` inside `run()`. `removeCallbacks` and the mechanism by which a `Looper` retrieves the head of the message queue are both governed by a lock. When `dispose()` is called on a non-main thread taking this lock is the race which determines cancelation and **not** the boolean. Include a comment emphasizing that the boolean is tracked solely for the purposes of accurate `isDisposed()` reporting.
|
We could optionally make the |
|
Hm, I'm not sure that reordering is a good idea, Also I'm pretty sure it's still possible to see I have an idea on how to not do // I'm on mobile, can elaborate later |
|
It takes time because it's the thing that's actual doing the cancelation. The boolean is redundant information solely for internal tracking purposes. |
|
Moreover, setting the boolean before |
|
Ah, I realize what you're likely going to post as I don't think I was clear. It's always the case that the boolean can be observed to be set while the runnable is running when they run concurrently. What this change does, however, is eliminate the ability for the boolean to reflect a state that's different than the real underlying race. That is, either |
This change ensures that you can never observe
disposedbeing set totrueinsiderun().removeCallbacksand the mechanism by which aLooperretrieves the head of the message queue are both governed by a lock. Whendispose()is called on a non-main thread taking this lock is the race which determines cancelation and not the boolean.Include a comment emphasizing that the boolean is tracked solely for the purposes of accurate
isDisposed()reporting.Refs #424.