Does a function is a thread?

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

Does a function is a thread?

29 Apr 2024, 09:43

Hallo.
I need to know if an UDF function is a thread, then, when it coloses, if the thread surely closes or not.
Thank you very much
User avatar
boiler
Posts: 17146
Joined: 21 Dec 2014, 02:44

Re: Does a function is a thread?

29 Apr 2024, 10:38

A function itself is not a thread. It is part of the code that is being executed as part of a thread. For example, you could call a function from the global code or from a hotkey function, and while it's executing that function, it's the same thread as what called it. The thread doesn't close when the called function closes because it never was its own thread. It just returns control back to where it was called from -- that being the global code space, a function, or whatever.

There is only one thread in this code:

Code: Select all

#Requires AutoHotkey v2.0

MsgBox 'This is the global code space, which is the main thread.'
MyFunc
MsgBox 'This is still the global code space.'
ExitApp

MyFunc() {
	MsgBox 'This is a function, and it is not a separate thread.  It did not interrupt the main thread.  It is being executed as part of the main thread.'
}
Archimede
Posts: 534
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Does a function is a thread?

29 Apr 2024, 10:48

Interesting, thank you very much.
I red the manual, but I no understanded, with precision,when a thread begins and when the same thread ends.
User avatar
mikeyww
Posts: 27149
Joined: 09 Sep 2014, 18:38

Re: Does a function is a thread?

29 Apr 2024, 11:10

Threads
The current thread is defined as the flow of execution invoked by the most recent event; examples include hotkeys, SetTimer subroutines, custom menu items, and GUI events. The current thread can be executing functions within its own subroutine or within other subroutines called by that subroutine.
Source: Threads - Behaviour & Priority | AutoHotkey v2
Archimede
Posts: 534
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Does a function is a thread?

29 Apr 2024, 11:24

:-)
I red it, but it explain only some examples: is there a list of all possible cases? Or what is, with precision, an event?
User avatar
mikeyww
Posts: 27149
Joined: 09 Sep 2014, 18:38

Re: Does a function is a thread?

29 Apr 2024, 11:31

I agree that the description is vague. I have relied on the specific examples provided and never encountered anything unexpected, different, or additional. Others may be able to provide greater clarity. I do think of these as events, but a function is not an event. An event is something that happens! A hotkey or GUI action is triggered. A timer is started. A menu is displayed. Well, I have no better words....
Archimede
Posts: 534
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Does a function is a thread?

29 Apr 2024, 11:36

:-)
Thank you.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: jakkaas, songdg, vmech and 32 guests