Author Topic: Scriptbasic Build Linux  (Read 62433 times)

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: Scriptbasic Build Linux
« Reply #165 on: January 21, 2019, 12:50:47 PM »
It sounds like mixing instances, because the sb64, freshly installed on a VM, works fine.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #166 on: January 21, 2019, 12:55:53 PM »
My asynchronous threaded example is returning this error.

jrs@jrs-laptop:~/sb/examples/test$ scriba sbt_main.sb
Main: 1
*** stack smashing detected ***: <unknown> terminated
Aborted (core dumped)
jrs@jrs-laptop:~/sb/examples/test$


Can you try this on your system?


Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: Scriptbasic Build Linux
« Reply #167 on: January 21, 2019, 01:12:05 PM »
Post the code

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: Scriptbasic Build Linux
« Reply #169 on: January 21, 2019, 02:05:25 PM »
SB_msSleep is causing the crash in the main file.

In the threaded file, it can't find the sbt include file when it's called from the main file.  When executed directly, it finds the include file.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #170 on: January 21, 2019, 02:11:35 PM »
Code: ScriptBasic
  1. SB_ThreadStart("sbt_thread.sb", "1","/etc/scriba/basic.conf")
  2.  

That should tell the new SB thread where the basic.conf is,

This use to work before I upgraded to 18.04.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #171 on: January 21, 2019, 02:18:09 PM »
I remarked out the SB_msSleep in both main and thread, it works using my passed basic.conf reference,

What do you think broke in SB_msSleep?


jrs@jrs-laptop:~/sb/examples/test$ scriba sbt_main.sb
Main: 1
Main: 2
Main: 3
Main: 4
Main: 5
Main: 6
Main: 7
Main: 8
Main: 9
Main: 10
T-1 : 1
T-1 : 2
T-1 : 3
T-1 : 4
T-1 : 5
T-1 : 6
T-1 : 7
T-1 : 8
T-1 : 9
T-1 : 10
T-2 : 1
T-2 : 2
T-2 : 3
T-2 : 4
T-2 : 5
T-2 : 6
T-2 : 7
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$

« Last Edit: January 21, 2019, 02:20:41 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: Scriptbasic Build Linux
« Reply #172 on: January 21, 2019, 02:33:18 PM »
I had to do this, since I use the sourced sb.sh script:

Code: ScriptBasic
  1. SB_ThreadStart("sbt_thread.sb", "1",ENVIRON("SCRIBACONF"))

But the order of output is different:

T-1 : 1
T-1 : 2
T-1 : 3
T-1 : 4
T-1 : 5
T-1 : 6
T-1 : 7
T-1 : 8
T-1 : 9
T-1 : 10
Main: 1
Main: 2
Main: 3
Main: 4
Main: 5
Main: 6
Main: 7
Main: 8
Main: 9
Main: 10
T-2 : 1
T-2 : 2
T-2 : 3
T-2 : 4
T-2 : 5
T-2 : 6
T-2 : 7
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


No idea why usleep is an issue.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #173 on: January 21, 2019, 02:39:24 PM »
Does it work on the Mac?

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #174 on: January 21, 2019, 03:33:46 PM »
This fixed it.

Note: I had to increase the wait to 50 from 10 so the screen output wasn't trashed.

Code: C
  1. besFUNCTION(SB_msSleep)
  2.   //DIM AS int msval, t;
  3.   DIM AS long t;
  4.   besARGUMENTS("i")
  5.     AT t
  6.   besARGEND
  7.   usleep(t);
  8.   besRETURNVALUE = NULL;
  9. besEND
  10.  


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

« Last Edit: January 21, 2019, 04:24:33 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #175 on: January 21, 2019, 11:16:59 PM »
I wanted to mention that asynchronous SB threads can be rerun and the variables reset just like the synchronous method.

Both methods can use MT for a common shared variable pool. (R/W lockable)  A great way to keep track of the status of threads.

Code: ScriptBasic
  1. IMPORT sbt.sbi
  2.  
  3. sb = SB_ThreadStart("catstr.sb", "","/etc/scriba/basic.conf")
  4. sb_msSleep(10)
  5. PRINT SB_GetVar(sb, "main::a"),"\n"
  6.  
  7. SB_Run sb, ""
  8. sb_msSleep(10)
  9. PRINT SB_GetVar(sb, "main::a"),"\n"
  10.  
  11. SB_ResetVars sb
  12. SB_Run sb, ""
  13. sb_msSleep(10)
  14. PRINT SB_GetVar(sb, "main::a"),"\n"
  15.  
  16. SB_Destroy sb
  17.  

catstr.sb
Code: ScriptBasic
  1. a &= "ABC"
  2.  



jrs@jrs-laptop:~/sb/examples/test$ scriba runthread.sb
ABC
ABCABC
ABC
jrs@jrs-laptop:~/sb/examples/test$


« Last Edit: January 22, 2019, 01:16:29 AM by John »

Mike Lobanovsky

  • Guest
Re: Scriptbasic Build Linux
« Reply #176 on: January 22, 2019, 04:36:44 AM »
Both methods can use MT for a common shared variable pool. (R/W lockable)

I'm afraid this statement isn't true, at least your script listing reads to the contrary. You see, your sb_msSleep(10) in the main thread enables the worker thread to write a new value into main::a unhindered while the main thread idles for almost 10 milliseconds and thus gives no chance to its subsequent read access to main::a in SB_GetVar() to collide with the worker thread's concurrent write access to the same. A write access to a single memory variable will take on the order of a few nanoseconds only, which is incongruously faster than the main thread's 10 millisecond idle period, thus precluding efficiently the said collision without any special alleged read/write locks on behalf of SB memory manager.

From what I used to see in the SB memory manager code, there were no access collision prevention options there. (they would inevitably slow things down for single-threaded applications where memory mutexing isn't necessary)

So, it isn't the SB memory manager that resolves the R/W access conflict automatically, but rather your own code, even if you don't fully realize it.

Now generally, what happens if you specify sb_msSleep(0)? (that is, out of this particular code context)

Under Windows, Sleep(0) has a special meaning of "yield the rest of own time slice to the other concurrent threads in the process", so that they could run faster/longer while the given thread idles on account of its task having been already fulfilled. The duration of thread time slices is normally scheduled by the system Task Manager automatically based on the number and priority of all threads in the process, but Sleep(0) can override this default behavior.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #177 on: January 22, 2019, 08:31:41 AM »
Mike,

Please read the docs for the MT extension module.

https://www.scriptbasic.org/docs/mt/mod_mt_toc.html
« Last Edit: January 22, 2019, 08:45:32 AM by John »

Mike Lobanovsky

  • Guest
Re: Scriptbasic Build Linux
« Reply #178 on: January 22, 2019, 12:53:59 PM »
I did -- until I came to this quotation: "For this the program should call LockWrite, LockRead and to unlock UnlockWrite, UnlockRead ...", then stopped. Doesn't it look like it's the program that's responsible for setting up the mutexes rather than the memory manager?

Which means the memory manager remains, er, unmanaged thread-wise in the absence of programmer's attention. Though yes, I admit Peter made his memory manager design and implementation as clean as he only could to facilitate the programmer's task and preclude inadvertent conflicts/clashes in the interpreter inner code due to careless and purblind design solutions.

So, what sb_msSleep(0) would mean in Linux if at all possible?

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Scriptbasic Build Linux
« Reply #179 on: January 22, 2019, 03:39:47 PM »
MT is used by threads to inform status. usleep(0) has a null affect.

You are correct that it's up to the SB programmer to use threads wisely.
« Last Edit: January 22, 2019, 03:52:13 PM by John »