[Python-Dev] tiny optimization in ceval mainloop
Tim Peters
tim.one@comcast.net
Fri, 30 Aug 2002 11:20:17 -0400
[Jack Jansen]
> Not if the idea that lead to this thread (clearing ticker if something
> is put in things_to_do) is implemented, because we may be in an
> interrupt routine at the time we fiddle things_to_do.
>
> And I don't think we can be sure that even clearing is guaranteed to
> work (if another thread is halfway a load-decrement-store sequence the
> clear could be lost).
So long as the ticker is declared volatile, the odds of setting ticker to 0
in Py_AddPendingCall during a "bad time" for --ticker are small, a window of
a couple machine instructions. Ticker will eventually go to 0 regardless.
It's not like things_to_do isn't ignored for "long" stretches of time now
either: Py_MakePendingCalls returns immediately unless the thread with the
GIL just happens to be the main thread. Even if it is the main thread,
there's another race there with some non-main thread happening to call
Py_AddPendingCall at the same time.
Opening another hole of a couple machine instructions shouldn't make much
difference, although Py_MakePendingCalls should also be changed then to
reset ticker to 0 in its "early exit because the coincidences I'm relying on
haven't happened yet" cases.