Author Topic: Scriptbasic Build Linux  (Read 2960 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2390
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #180 on: January 22, 2019, 11:24:33 PM »
I tried removing the MAIN loop and changed sb_msSleep to 1.


jrs@jrs-laptop:~/sb/examples/test$ scriba sbt_main.sb
T-1 : 1
T-1 : 2
T-2 : 1
T-1 : 3
T-2 : 2
T-1 : 4
T-2 : 3
T-1 : 5
T-2 : 4
T-1 : 6
T-2 : 5
T-1 : 7
T-1 : 8
T-2 : 6
T-2 : 7
T-1 : 9
T-1 : 10
T-2 : 8
T-2 : 9
T-2 : 10
T-3 : 1
T-3 : 2
T-3 : 3
T-3 : 4
T-3 : 5
T-3 : 6
T-3 : 7
T-3 : 8
T-3 : 9
T-3 : 10
jrs@jrs-laptop:~/sb/examples/test$


Offline Mike Lobanovsky

  • ON-HOLD
  • BASIC Developer
  • Posts: 261
Re: Scriptbasic Build Linux
« Reply #181 on: January 23, 2019, 01:27:44 AM »
For an interpreter, the theoretically ultimate shortest sleep period will be determined by how complicated and slow (or simple and fast) the interpreter implementation is regarding its read/write access to a memory location defined in the BASIC code.

To speed things up still further, you may try and exclude sb_msSleep() periods altogether. As per the script, each worker thread increments and prints its own X variable so there are no cross-thread read/write access conflicts possible in this setup.

OTOH if each of the threads were to increment, and print the current value of, a global shared variable, then their respective accesses to it in the PRINT statement should be enclosed in Lock/UnlockWrite calls to prevent another thread's possible concurrent incrementation of the shared variable that would cause a memory access violation (segfault). Similarly, a write access to the shared variable to increment it should prevent concurrent reads by framing the incrementation code with Lock/UnlockRead. I think the sleep periods could then be safely omitted as well. But this is only my supposition that needs further investigation.

A few microseconds to make a couple interpretative calls to Lock/Unlock would still be much faster than the 1000 microseconds that usleep(1) defines.

[UPD] Unlike MS Windows Sleep(1), the Linuxoid usleep(1) defines a 1-microsecond, not 1-millisecond, time lapse... :o
« Last Edit: January 23, 2019, 07:37:55 PM by Mike Lobanovsky »
Mike
____________________________________________________________________
(3.6GHz Intel Core i5, 16GB RAM / nVidia GTX 1060Ti , 6GB VRAM / x64 Win7 Ult.)

Offline John

  • Forum Support / SB Dev
  • Posts: 2390
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #182 on: January 23, 2019, 09:24:49 AM »
I need to look at sbhttpd a little closer to see how Peter dealt with this issue. At least BASIC threads is working on multiple platforms.

Each thread is it's own instance of SB that can have it's own set of extension modules. That is what makes this so cool.
« Last Edit: January 23, 2019, 09:44:56 AM by John »

Offline Mike Lobanovsky

  • ON-HOLD
  • BASIC Developer
  • Posts: 261
Re: Scriptbasic Build Linux
« Reply #183 on: January 23, 2019, 07:49:38 PM »
I've just learnt that usleep() specifies time lapses in microseconds rather than milliseconds (times 1000 microseconds).

I'm afraid it makes usleep-dependent code non-portable to Windows as-is unless linked against the POSIX Threads for Windows library (which goes under LGPL)... ::)
Mike
____________________________________________________________________
(3.6GHz Intel Core i5, 16GB RAM / nVidia GTX 1060Ti , 6GB VRAM / x64 Win7 Ult.)

Offline John

  • Forum Support / SB Dev
  • Posts: 2390
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #184 on: January 24, 2019, 04:02:55 PM »
I think using MT and assigning a priority, a well managed multi-threaded environment could be achieved. BASIC programmers would have to design their code with a sharing frame of mind.

1 - Run until thread competes
2 - Share CPU with other SB threads
3 - Only run if no other SB threads are active
« Last Edit: January 24, 2019, 04:07:24 PM by John »

Offline Mike Lobanovsky

  • ON-HOLD
  • BASIC Developer
  • Posts: 261
Re: Scriptbasic Build Linux
« Reply #185 on: January 24, 2019, 06:07:00 PM »
I think virtually all modern BASIC translators and JIT or static compilers that are equipped with their own machine code generators (VB.NET, PowerBASIC, FBSL, OxygenBasic) or use 3rd party asm or C compiler back ends (FreeBASIC, BCX and clones) are suitable for successful multithreaded code generation.

Which means that there should already be a sufficient BASIC user base who are aware of that facility and are using it in their creative work in accordance with their main objectives.
Mike
____________________________________________________________________
(3.6GHz Intel Core i5, 16GB RAM / nVidia GTX 1060Ti , 6GB VRAM / x64 Win7 Ult.)

Offline John

  • Forum Support / SB Dev
  • Posts: 2390
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #186 on: January 24, 2019, 09:34:16 PM »
Mike,

Would you be willing to put together an example how SB theads can be used other than a FOR/NEXT loop in unison? The SB Inno Windows install has SBT included.

Maybe this would make a good code challenge. AIR, what do you think?
« Last Edit: January 24, 2019, 10:07:08 PM by John »