Interruption by another thread

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Archimede
Posts: 675
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Interruption by another thread

Post by Archimede » 29 Apr 2024, 10:51

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?

User avatar
mikeyww
Posts: 28870
Joined: 09 Sep 2014, 18:38

Re: Interruption by another thread

Post by mikeyww » 29 Apr 2024, 11:08

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.

Archimede
Posts: 675
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Interruption by another thread

Post by Archimede » 29 Apr 2024, 11:34

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.

User avatar
mikeyww
Posts: 28870
Joined: 09 Sep 2014, 18:38

Re: Interruption by another thread

Post by mikeyww » 29 Apr 2024, 11:37

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.

lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: Interruption by another thread

Post by lexikos » 02 May 2024, 21:28

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

Post Reply

Return to “Ask for Help (v2)”