Page 1 of 1
Interruption by another thread
Posted: 29 Apr 2024, 10:51
by Archimede
If I have a multi line like (only to understand)
Code: Select all
iTest :=1
, iTest2 := 2
, iTest3 :=3
that multi line is red on one time; when it is red, and before it is executed all, can it interrupted by another thread?
Re: Interruption by another thread
Posted: 29 Apr 2024, 11:08
by mikeyww
Hello,
You might want to test your idea through a script, and read the documentation about threads. You can change interruptibility by changing thread priority or using
Critical.
Re: Interruption by another thread
Posted: 29 Apr 2024, 11:34
by Archimede
I know Critical.
I need to understand when it is necessary to use it and when is not necessary: it is useful when need to write a very fast program.
Re: Interruption by another thread
Posted: 29 Apr 2024, 11:37
by mikeyww
Without Critical, a hotkey can interrupt a hotkey's subroutine (for example).
Write a test script so that you can see it in action. The time required is about 2 minutes.
Re: Interruption by another thread
Posted: 02 May 2024, 21:28
by lexikos
If you need to
guarantee that it will not be interrupted, you must rely on documented behaviour, not just practical observations or knowledge of undocumented behaviour. Critical gives the clearest guarantee, and shows your intent. You should use it.
The code at the top is exactly equivalent to:
Code: Select all
iTest :=1, iTest2 := 2, iTest3 :=3
A single expression has fewer chances of interruption than separate expressions, but calling a function can still cause interruption.
Specifying a positive number as the first parameter (e.g. Critical 30) turns on Critical but also changes the minimum number of milliseconds between checks of the internal message queue. [...]. Increasing the interval postpones the arrival of messages/events, which gives the current thread more time to finish. [...]
This setting affects the following:
- Preemptive message checks, which potentially occur before each line of code executes.
- Periodic message checks during Send, file and download operations.
Source: Critical - Syntax & Usage | AutoHotkey v2