Author Topic: SBT  (Read 35396 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Re: SBT
« Reply #75 on: May 02, 2015, 10:40:37 AM »
Charles,

So far the SBT (Script BASIC Tutorial) extension/embedding module stands with nothing on the issues list.  :)

I'm combining the SB_Set(type) functions to a single SB_SetVar function and then putting the happy C BASIC face on the interface that is still showing its C side. I hope to have that done in a couple hours.

The next goal is to get SB preprocessor support working so I can use this for the next part of the tutorial which is building a GUI (IUP) editor/debugger. (like Dave's effort without the COM) In conjunction I would like to get the SB embedded objects running in a threaded model. You have already been down this road with DLLC and your wealth of SB knowledge would help make this go smoother.

The SBT project is becoming fragmented trying to run parallel threads here on O2 and All BASIC. You are a long time member on All BASIC and it would be great if you can join AIR, Mike, Markus, Tony and I along with any of the other BASIC developers that might join in.

I have had e-mail contact with Peter Verhas but I think he is only able to lurk at the moment due to other commitments.


JRS

  • Guest
Re: SBT
« Reply #76 on: May 04, 2015, 09:52:02 AM »
Hi Charles,

I have been looking at Dave's debugger.c/h (sb_engine.dll) and there is a lot of good stuff in there. I might be missing something but I can't see why I can't scriba_NoRun the script and use some of Dave's debug code to single step through the script. That is my first goal at the moment. I don't think an internal preprocessor is needed as we aren't trying to inject a debugger as a filter of sorts in normal code execution flow.

I think I want to do a TRACE(ON|OFF) internal preprocessor for the that part of the tutorial. Debugging (interactive mode) should be a core feature of the SBT API.

Can you take a peek at Dave's sb_engine.dll code and see how I might adapt a single step feature to SBT?
« Last Edit: May 04, 2015, 10:22:30 AM by John »

Charles Pegge

  • Guest
Re: SBT
« Reply #77 on: May 05, 2015, 10:12:35 AM »
Hi John,

I cannot accommodate any further coding activities, than I already have. Sorry.

JRS

  • Guest
Re: SBT
« Reply #78 on: May 05, 2015, 11:03:15 AM »
I see this debugging API (internal preprocessor) as a way to make SB an interactive BASIC. If someone were interested in that direction, this would be the way to do it. With Dave's IDE/Debugger + VB classic / COM and the sdbg console debugger I have going on Linux, I think this is far as I want to go with this on a tutorial level. Preprocessors are advanced SB usage.

Thanks Charles for all the help and code you have contributed to the Script BASIC project!

« Last Edit: May 05, 2015, 12:16:59 PM by John »

JRS

  • Guest
Re: SBT
« Reply #79 on: May 06, 2015, 10:24:04 PM »
I finally got the Script BASIC remote console debugger working and with arrays8)

All BASIC Example

JRS

  • Guest
Re: SBT
« Reply #80 on: May 07, 2015, 11:25:12 AM »
Got it working on Windows 32 (XP) as well.

(see All BASIC forum)

JRS

  • Guest
Re: SBT
« Reply #81 on: May 14, 2015, 12:09:45 AM »
Charles,

I got SBT working multi-threaded.

(see All BASIC forum)

Charles Pegge

  • Guest
Re: SBT
« Reply #82 on: May 14, 2015, 01:56:53 AM »
Well done! Is it collision-proof ?

JRS

  • Guest
Re: SBT
« Reply #83 on: May 14, 2015, 02:11:05 AM »


Quote
Is it collision-proof ?

Don't know. Just fired up the reactor.  ;D

I did some Gtk test with sbhttpd/cURL some time ago and it seemed to handle multiple event loop handlers. I should know more tomorrow and if MT works.

Found the old post. January 04, 2011

Quote
Here is an update on my threaded Gtk adventures.

I was having a problem with GTK-Server / SB missing events within the gtk_server_callback WAIT routine in my scripts. I ended up adding the gdk_threads_enter/leave routine to GTK-Server's C code.

gtk-server.c
Code: C
  1.     /* Have we found the GTK-signal call? */
  2.     else if (!strcmp("gtk_server_callback", gtk_api_call)) {
  3.         /* Yes, find the first argument */
  4.         if ((arg = parse_data(list, ++item)) != NULL){
  5.             while (1){
  6.                 /* Let GTK wait for an event <<-- JRS --->> Thread enter/leave added */
  7.                 if (!strcmp (arg, "WAIT") || !strcmp (arg, "wait") || !strcmp(arg, "1")) {
  8.                     #if GTK_SERVER_GTK1x || GTK_SERVER_GTK2x
  9.                     gdk_threads_enter ();
  10.                     gtk_main_iteration();
  11.                     gdk_threads_leave ();
  12.                     #elif GTK_SERVER_XF
  13.                     Current_Object.object = fl_do_forms();
  14.                     Current_Object.state = (long)Current_Object.object;
  15.                     #endif
  16.  

This is my current working code.

mtgtk.sb
Code: Script BASIC
  1. PRINT "Status: 200\nContent-Type: text/html\n\n"
  2.  
  3. DECLARE SUB MTSET ALIAS "setmtvariable" LIB "mt"
  4. DECLARE SUB MTGET ALIAS "getmtvariable" LIB "mt"
  5.  
  6. IF MTGET("tid") = undef THEN
  7.   MTSET("tid",1)
  8.   tid = MTGET("tid")
  9. ELSE
  10.   tid = MTGET("tid") + 1
  11.   MTSET("tid",tid)
  12. END IF
  13.  
  14. DECLARE SUB DLL ALIAS "_idll" LIB "gtk-server"
  15. DECLARE SUB DEFINE ALIAS "_idll_define" LIB "gtk-server"
  16.  
  17. DEFINE "gtk_init NONE NONE 2 NULL NULL"
  18. DEFINE "gtk_window_new delete-event WIDGET 1 INT"
  19. DEFINE "gtk_window_set_title NONE NONE 2 WIDGET STRING"
  20. DEFINE "gtk_table_new NONE WIDGET 3 INT INT BOOL"
  21. DEFINE "gtk_container_add NONE NONE 2 WIDGET WIDGET"
  22. DEFINE "gtk_button_new_with_label clicked WIDGET 1 STRING"
  23. DEFINE "gtk_table_attach_defaults NONE NONE 6 WIDGET WIDGET INT INT INT INT"
  24. DEFINE "gtk_widget_show_all NONE NONE 1 WIDGET"
  25. DEFINE "gtk_server_callback NONE STRING 1 STRING"
  26. DEFINE "gtk_widget_destroy NONE NONE 1 WIDGET"
  27. DEFINE "g_thread_init NONE NONE 1 NULL"
  28. DEFINE "g_thread_exit NONE NONE 1 NULL"
  29. DEFINE "gdk_threads_init NONE NONE 0"
  30. DEFINE "gdk_threads_enter NONE NONE 0"
  31. DEFINE "gdk_threads_leave NONE NONE 0"
  32.  
  33. DLL("g_thread_init")
  34. DLL("gdk_threads_init")
  35. DLL("gdk_threads_enter")
  36. DLL("gtk_init NULL NULL")
  37. win = DLL("gtk_window_new 0")
  38. DLL("gtk_window_set_title " & win & " \"SB Gtk " & tid & "\"")
  39. tbl = DLL("gtk_table_new 10 10 1")
  40. DLL("gtk_container_add " & win & " " & tbl)
  41. but = DLL("gtk_button_new_with_label \"Quit\"")
  42. DLL("gtk_table_attach_defaults " & tbl & " " & but & " 5 9 5 9")
  43. DLL("gtk_widget_show_all " & win)
  44. DLL("gdk_threads_leave")
  45.  
  46. REPEAT
  47.   event = DLL("gtk_server_callback WAIT")
  48. UNTIL event = win OR event = but
  49.  
  50. DLL("gdk_threads_enter")
  51. DLL("gtk_widget_destroy " & win)
  52. DLL("gtk_server_callback 2")
  53. DLL("gdk_threads_leave")
  54. DLL("g_thread_exit NULL")
  55.  
  56. END
  57.  



This is a screen shot of starting 4 Gtk threaded windows from a scriba script.

mtdemo.sb
Code: Script BASIC
  1. INCLUDE curl.bas
  2.  
  3. ch = curl::init()
  4.  
  5. curl::option(ch,"NOBODY")
  6. curl::option(ch,"URL","http://127.0.0.1:8080/mtsb/mtgtk.sb")
  7. curl::perform(ch)
  8.  
  9. curl::finish(ch)
  10.  

My initial testing is looking positive and I will try something more complex other than just a window with a quit button.

FYI If I run a GTK-Server SB script in a non-threaded environment, the gdk_threads_enter/leave I coded into gtl_server_callback WAIT doesn't seem to have any side effects.

I'm amazed that this even works at all. Gtk running in a threaded environment using a scripted API interface is pushing the envelope with an interpreter. When I tried creating the second thread for the first time and got a Linux GUI sub-system error, I thought I was toast. I hope this effort encourages the BCX team to have a look at threading Gtk.

I would love to see how this runs on a multi-core processor. I'm not seeing any abnormal CPU or memory use when running in a threaded Gtk environment.
« Last Edit: May 14, 2015, 02:37:34 AM by John »

JRS

  • Guest
Re: SBT
« Reply #84 on: May 14, 2015, 04:44:35 PM »
Here is an example of using the MT extension module to communicate between threads and the host script.

ttmain.sb
Code: Script BASIC
  1. IMPORT mt.bas
  2. IMPORT sbt.inc
  3.  
  4. SB_ThreadStart("tt1.sb", "JRS","/etc/scriba/basic.conf")
  5. PRINT "SB Host\n"
  6. LINE INPUT wait
  7. PRINT mt::GetVariable("thread_status"),"\n"
  8.  

tt1.sb
Code: Script BASIC
  1. ' Test Thread
  2.  
  3. IMPORT mt.bas
  4. IMPORT sbt.inc
  5.  
  6. cmd = COMMAND()
  7. PRINT cmd,"\n"
  8.  
  9. FOR x = 1 TO 10
  10.   PRINT "Thread 1: ",x,"\n"
  11. NEXT
  12.  
  13. mt::SetVariable "thread_status","Completed"
  14.  
  15. SB_ThreadEnd
  16.  

Output

jrs@laptop:~/sb/sb22/sbt$ scriba ttmain.sb
SB Host
JRS
Thread 1: 1
Thread 1: 2
Thread 1: 3
Thread 1: 4
Thread 1: 5
Thread 1: 6
Thread 1: 7
Thread 1: 8
Thread 1: 9
Thread 1: 10

Completed
jrs@laptop:~/sb/sb22/sbt$
« Last Edit: May 14, 2015, 05:44:41 PM by John »

JRS

  • Guest
Re: SBT
« Reply #85 on: May 15, 2015, 07:21:17 PM »
Charles,

I gave IUP a try with SBT but it only allowed one thread at a time. Here is the error message I got. Can you give me an idea in general terms how you solved the collision issue in DLLC? This will give me the info and direction I need to fix this on Linux.


jrs@laptop:~/sb/sb22/sbt$ scriba iupmain.sb
SB Host

(scriba:1886): Gdk-WARNING **: scriba: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.

jrs@laptop:~/sb/sb22/sbt$ scriba iupmain.sb
SB Host

(scriba:2627): Gdk-ERROR **: The program 'scriba' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadDrawable (invalid Pixmap or Window parameter)'.
  (Details: serial 722 error_code 9 request_code 139 (RENDER) minor_code 4)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
Trace/breakpoint trap (core dumped)
jrs@laptop:~/sb/sb22/sbt$


Charles Pegge

  • Guest
Re: SBT
« Reply #86 on: May 15, 2015, 08:46:17 PM »
Hi John,

As I recall, only one procedure can be active in one sb program per thread at any one time. If you want concurrency then you must use additional sb programs, using SBT to manage them, and coordinate data.


JRS

  • Guest
Re: SBT
« Reply #87 on: May 15, 2015, 09:25:32 PM »
Even if I don't define any callbacks in my thread IUP test scripts, it still complains. It seems you can't have more than one IUP event loop running in a process. (which the threads are part of)

I don't see IupMainLoop() anywhere in DLLC code. Does this mean DLLC has it's own (ASM) IUP event loop?
« Last Edit: May 15, 2015, 10:08:43 PM by John »

Charles Pegge

  • Guest
Re: SBT
« Reply #88 on: May 15, 2015, 11:58:18 PM »
IupMainLoop() is called from the SB script, as a regular DLLC call. Thereafter, the program (running in its own thread), is dedicated to processing IUP callbacks and nothing else.

But the boot program continues to run, and is able to monitor the data captured from incoming IUP callback params.

The data is stored in a shared table (accessible by both programs).

« Last Edit: May 16, 2015, 12:06:45 AM by Charles Pegge »

JRS

  • Guest
Re: SBT
« Reply #89 on: May 16, 2015, 08:58:22 AM »
I can't seem to get more than one IupMainLoop() going. (Gtk / X-Windows errors) I didn't define any callbacks in the thread scripts. What is IUP specifically not willing to share?

It would be great to see an O2 only threaded IUP example which would not only help me but I'm sure Arnold would find it interesting and maybe expand on its use.

« Last Edit: May 16, 2015, 09:28:18 AM by John »