- Pass the PID along with each function call.
- Set the LastFoundWindow. This required all functions to always restore the 'last found window' if that function temporarily has to act on another window. The last found window is thread specific.
- Store the PID in a global variable. This is not stable when a thread can be interrupted by another thread which changes the global variable.
There are certain built-in variables that are thread specific, like
A_TitleMatchMode. To me it would be nice to be able to define my own thread specific variables. Variables that are global but only within the same thread. When another thread interrupts, it can define its own value for such variables, but it does not change anything for the thread that was interrupted.
Similar to the definition of super global variables
global var1, I would propose thread variables to be defined by
Besides the thread variables it is also helpful to have a unique ID for each thread within the script, e.g.
A_ThreadIDyou can for example store values in a global associative array and call
global PIDs[A_ThreadID]to retrieve thread specific values. I'm not sure if Autohotkey uses thread_id's internally, I think in that case it's a small step to make this value available to the script.