QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: doppler on October 02, 2018, 09:15:50 am
-
Is it possible to get QB64 to multi-thread ? I mean truly multi-thread.
I want to spawn subroutines to other processor cores. They can remain running.
All the proper signaling going back to the parent core. This is a big question because
of all the things that go along with SMP process's.
I expect it's up to the user to make sure, he/she does not throw a spawned process
into a tight loop and max out a core. And any error checking like finding a dead spawn
and kill the process. Last thought (dead spawn) who-ha, sounds more like a horror movie.
Thoughts?
-
Hi doppler,
Processes are assigned to the individual processor kernels by the operating system. It is possible to divide the main process into individual threads, but how to guarantee that individual threads will process specific kernels, I do not know. This division is perhaps only my programmer's pig .... pseudo code:
DO
process = process + 1
if process mod 2 = 0 then ------ this section applies to each second pass
if process mod 3 = 0 then ------ this section is used every third pass
if process> 3 then process = 0
LOOP
but it is necessary to take into account in this solution that process 4 is already divisible by two, so process 4 will be carried out simultaneously with process 2.
If someone writes a better solution, so please share!
-
Is it possible to get QB64 to multi-thread ? I mean truly multi-thread.
In short, no. Not as you'd expect a modern language to multithread.
An alternative approach is using multiple timers:
'setup timers:
_LIMIT 1 'main loop doing nothing so the timers can do their thing
myValue = myValue + 1
-
An alternative approach is using multiple timers
Thank you, yes, this is really a better solution!
-
I have to bookmark this. Since SMP is a pipedream in QB64 for now.
Curious, How many timers can be setup ? There has to be a limit.
-
Just as a follow-up to Fellippe's response, QB64 will probably never support true multithreading. It's incredibly hard for the programmer to get it right and has a habit of causing subtle bugs in even the simplest of programs.