Posts: 156
Threads: 14
Likes Received:
46 in 37 posts
Likes Given: 46
Joined: Oct 2023
Reputation:
3
11-26-2024, 12:56 PM
(This post was last modified: 11-26-2024, 01:07 PM by jrmrhrb00.)
Z-S,
If putting in a current thread property in your extension would work that would be great! Then we would really know.
JR
AB.
Your comments are right if in fact a subroutine does not call a different thread and stays in the UI thread when called.
JR
Posts: 156
Threads: 14
Likes Received:
46 in 37 posts
Likes Given: 46
Joined: Oct 2023
Reputation:
3
AB,
Question 1: If a subroutine is in fact called by the UI and actually runs in the UI. I am not really sure of that.
Question 2: I have read that the event handler runs only in the UI thread.
Question 3: Maybe a running subroutine will call another subroutine on the same thread.
Question 4: I don't know anything about LDCall.
The best guidance I have read on threading has came from LitDev. It is a very complex topic and really shouldn't be a part of the discussion for Small Basic.
Posts: 464
Threads: 37
Likes Received:
374 in 256 posts
Likes Given: 183
Joined: Aug 2023
Reputation:
17
Hi,
All subroutines run on the thread that they were called from, so a call to a subroutine and all child subroutines will be on the same thread as their top level parent.
The main program starts on the UI thread, so all subroutines called from it will also be on the UI thread.
With the exception of specific extension thread control, All EVENT subroutine start on their own (non UI thread), and therefore subroutine calls made from with an EVENT subroutine will also be on the event thread.
1] Yes, the main program is UI thread and all subroutines called from it also are.
2] Exactly the opposite, all event subroutines are NOT on the UI thread, they have their own
3] Yes, as above
4] LDCall can run things async (on a different thread)
One thing to note is that updates to the UI (e.g. moving a shape or anything else) will only take place on the UI thread. If such a UI update is made in an event subroutine, then it wil not actually be done until the event subroutine ends. Also, any variable changes made in event subroutines may conflict with asynchronos UI code (running at the same time, for example the same loop index 'i' may be over-writen by event sub while it is being used in UI thread). These are why I always suggest to do as little work in event sub as possible, just set a flag, and handle it in an 'game loop' on the main UI thread.
Posts: 156
Threads: 14
Likes Received:
46 in 37 posts
Likes Given: 46
Joined: Oct 2023
Reputation:
3
Thanks to Z-S and his extension here is a program that shows what thread is actually being used and for what function: XKMS572.000
The program is basically the first program in LitDev's Threading article. Modified a little bit.
JR
Posts: 156
Threads: 14
Likes Received:
46 in 37 posts
Likes Given: 46
Joined: Oct 2023
Reputation:
3
Z-S,
I have your new extension and tried using the thread functions and I couldn't get them to work. Could you give us some examples of how to use them?
Thanks,
JR
Posts: 156
Threads: 14
Likes Received:
46 in 37 posts
Likes Given: 46
Joined: Oct 2023
Reputation:
3
Z-S,
Thanks for the samples! They did get me started.
JR