Threads - Printable Version +- Small Basic Forum (https://litdev.uk/mybb) +-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1) +--- Forum: Standard Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=2) +--- Thread: Threads (/showthread.php?tid=160) Pages:
1
2
|
RE: Threads - AbsoluteBeginner - 11-26-2024 (translated by Google translator) Hello, JR If I understood you correctly, then now everything works as you described.
If the event handler calls any subroutine, then this subroutine will also be executed in the handler thread ( that is, in a parallel thread ). I hope I haven't made a mistake anywhere. RE: Threads - jrmrhrb00 - 11-26-2024 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 RE: Threads - AbsoluteBeginner - 11-26-2024 (11-26-2024, 12:56 PM)jrmrhrb00 Wrote: AB.(translated by Google translator) JR, I suggest discussing everything as precisely as possible. This might be useful for someone else learning Small Basic. There are two different objects in my consciousness:
But, the event handler runs in its own parallel thread. A running subroutine calls another subroutine on the same thread on which it itself is running. To call another subroutine in a new thread, you must use the LDCall.CallAsync(dll, extension, obj, method, arguments) method. Do you agree? RE: Threads - jrmrhrb00 - 11-26-2024 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. RE: Threads - litdev - 11-26-2024 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. RE: Threads - jrmrhrb00 - 11-29-2024 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 RE: Threads - z-s - 11-30-2024 If you have latest zs extension version you could play with this. ZSThreading : for multiple threads in sb ZSTask : for asynchronous non blocking function different from thread https://en.m.wikipedia.org/wiki/Asynchrony_(computer_programming) RE: Threads - jrmrhrb00 - 12-01-2024 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 RE: Threads - z-s - 12-02-2024 ZSTHREAD SAMPLE Code: TextWindow.WriteLine(ZSUtilities.GetCurrentManagedThreadId()) ZSTASK SAMPLE Code: TextWindow.WriteLine(ZSUtilities.GetCurrentManagedThreadId()) RE: Threads - jrmrhrb00 - 12-02-2024 Z-S, Thanks for the samples! They did get me started. JR |