Threads

A thread is a running macro or function. All functions it calls run in the same thread.

 

Generaly, a thread is the basic unit to which the operating system allocates CPU time. It executes code. Each thread runs simultaneously with other threads. Every process (running program) has one or more threads. To create effect of several simultaneously running threads, operating system divides CPU time into time slices (~20 ms). It allocates a CPU time slice to each thread that need it. The currently executing thread is suspended when its time slice elapses, allowing another thread to run. If there are multiple CPU, threads may run simultaneously on different CPU.

 

QM creates new thread for each macro or function started by the user. It also creates new thread for menu items. When you use mac to run a macro or function, it also runs in new thead. Timer functions (tim) also run in new threads everytime.

 

QM allows to run 1 macro and any number of functions at a time. All they run in their own threads. Several instances of the same function also can run simultaneously, because each runs in its own thread.

 

All currently running threads, except special threads, are displayed in the Running Items list. To see the list, check View Active Items in the Run menu. To see threads without opening QM window, use QM tray menu. See also: EnumQmThreads.

 

Special threads

 

There are two threads that run all the time:

 

1. QM main thread. Functions that run in it: global variable constructors/destructors, toolbar hook functions, functions executed during compilation and some other functions. Also, a macro or other application can send message to run a function in the main thread.

2. Thread of filter functions. All filter functions of key, mouse and window triggers run in this thread.

 

Threads also can be explicitly or implicitly created using some dll functions.

 

In special threads, don't use atend. Functions registered with atend will not run.

 

In threads created by dll functions, avoid using thread variables. They will not be destroyed.

 

In other special threads, thread variables will be destroyed when unloading current qml file, before destroying global variables (QM 2.3.0). In older QM versions, thread variables should not be used in special threads.