[SOLVED] Thread with multiple processing loops

Just starting out? Need help? Post your questions and find answers here.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

[SOLVED] Thread with multiple processing loops

Post by boddhi »

Hello,

Note: The use and programming of threads is still a bit of a mystery to me. I'm gradually trying to understand and learn how to use them :) .

I have a question about the best way to proceed in the following case:
A first loop retrieves data by sending an indeterminate number of HTTP requests. Once this is done, another loop performs some processing on the data.
My question is whether it's better to manage both loops within a single thread or to launch two threads for each of them (Thread → Loop 1 → End of thread → New thread → Loop 2 → End of thread) ?

Thanks for your answers.
Last edited by boddhi on Mon May 26, 2025 9:56 pm, edited 1 time in total.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Thread with multiple processing loops

Post by mk-soft »

Since this is performed in a sequence in a sequence, a single thread is sufficient
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Thread with multiple processing loops

Post by boddhi »

mk-soft wrote: Since this is performed in a sequence in a sequence, a single thread is sufficient
Thanks for your reply :wink:

Another (noob's) question: I understand that you have to use a memory address (to a string or a structure) when you want to pass non-numeric parameters through a PostEvent.
I see in your example #5 that you use it to feed a ListView.
In my code, I feed my gadgets designed to receive text (TextGadget, StringGadget, ListIcon, etc.) with dedicated commands (SetGadgetText, ...) directly from the threaded procedure. This works well.
Is this not recommended as I do, and if so, why or both methods are possible ?

Thanks in adavnce.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Thread with multiple processing loops

Post by mk-soft »

boddhi wrote: Sun May 25, 2025 10:20 pm Another (noob's) question: I understand that you have to use a memory address (to a string or a structure) when you want to pass non-numeric parameters through a PostEvent.
I see in your example #5 that you use it to feed a ListView.
In my code, I feed my gadgets designed to receive text (TextGadget, StringGadget, ListIcon, etc.) with dedicated commands (SetGadgetText, ...) directly from the threaded procedure. This works well.
Is this not recommended as I do, and if so, why or both methods are possible ?
With Windows it works in most cases. But as soon as you switch to Linux or macOS, it crashes.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Thread with multiple processing loops

Post by boddhi »

mk-soft wrote: With Windows it works in most cases. But as soon as you switch to Linux or macOS, it crashes.
Thanks a lot for all these explanations.

However, I must admit that I don't always understand why some actions on gadgets, depending on where they are placed in the threaded procedure, work or don't work. I find other ways of getting things done.
Maybe it's due to the timeout used with WaitThread...
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: [SOLVED] Thread with multiple processing loops

Post by jacdelad »

Most actions, if not all, performed on gadgets shouldn't be done within a thread, but outside of it, triggered by a message. However, there's a mk-spft-code floating around in the Tips & Tricks sub forum, which addresses this especially for threads. Worth a look.

Also, without code it's hard to say why your code does not always work...
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: [SOLVED] Thread with multiple processing loops

Post by boddhi »

Hello jacdelad
jacdelad wrote: there's a mk-spft-code floating around in the Tips & Tricks sub forum, which addresses this especially for threads. Worth a look.
Probably the one I was referring to when I mentioned example #5 :wink: ( :oops: ouupss, I seem to have forgotten to mention it in this post: it's here).
jacdelad wrote: Also, without code it's hard to say why your code does not always work...
I know, I know... :wink: but, even if it's related to one of my codes, my questions were of a general nature, to better understand how threads work. Given the length of the code and the many procedures called, it might have been complicated to isolate or reproduce the problem I was having.
I don't claim to have understood everything about threads yet, but I followed some mksoft's advices and was able to get the result I wanted without any crashes :D .
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Post Reply