Author Topic: Crazy SMP question, maybe not so much.  (Read 3542 times)

0 Members and 1 Guest are viewing this topic.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Crazy SMP question, maybe not so much.
« 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?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Crazy SMP question, maybe not so much.
« Reply #1 on: October 02, 2018, 09:53:15 am »
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!
« Last Edit: October 02, 2018, 09:58:33 am by Petr »

Marked as best answer by doppler on October 02, 2018, 07:53:23 am

FellippeHeitor

  • Guest
Re: Crazy SMP question, maybe not so much.
« Reply #2 on: October 02, 2018, 10:02:45 am »
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:

Code: QB64: [Select]
  1.  
  2. 'setup timers:
  3. displayThread = _FREETIMER
  4. calcThread = _FREETIMER
  5. ON TIMER(displayThread, .03) show
  6. ON TIMER(calcThread, .03) calc
  7. TIMER(calcThread) ON
  8. TIMER(displayThread) ON
  9.  
  10.     _LIMIT 1 'main loop doing nothing so the timers can do their thing
  11.  
  12. SUB show
  13.     CLS
  14.     PRINT myValue
  15.     _DISPLAY
  16.  
  17. SUB calc
  18.     myValue = myValue + 1

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Crazy SMP question, maybe not so much.
« Reply #3 on: October 02, 2018, 10:24:46 am »
Quote
An alternative approach is using multiple timers
Thank you, yes, this is really a better solution!

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Crazy SMP question, maybe not so much.
« Reply #4 on: October 02, 2018, 10:50:10 am »
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.
« Last Edit: October 02, 2018, 10:53:09 am by doppler »

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Crazy SMP question, maybe not so much.
« Reply #5 on: October 03, 2018, 10:47:34 am »
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.