Programm is simply closeing but.. why??

General FreeBASIC programming questions.
mrminecrafttnt
Posts: 86
Joined: Feb 11, 2013 12:23

Programm is simply closeing but.. why??

Postby mrminecrafttnt » Dec 12, 2018 19:23

I am try to make an auto restarting sub after an crash but it will simply close my programm without errors?? I don't know why it will do this.. ?
This is mytherious.. :/

Code: Select all

#define thread_uninitalized 0
#define thread_running 1
#define thread_crashed 2

type thread_controller
    state as uinteger
    declare sub reboot(t_adress as any ptr,byref state as uinteger)
end type

sub thread_controller.reboot(t_adress as any ptr,byref state as uinteger)
    PRINT "REBOOTING..";
    if state = thread_crashed then
        PRINT "EXECUTE..";
        threadcreate t_adress
        sleep 100
        if state = thread_running then print "REBOOT SUCCESFULL" ELSE PRINT "SOMETHING IS WORONG."
    else
        print "NO REASON TO REBOOT"
    end if
end sub



sub instable_thread
    PRINT "INSTABLE THREAD IS RUNNING NOW"
    static as integer threads
    static as integer reboot_state
    threads+=1
    on error goto error_handler
    dim as thread_controller ctrl
    ctrl.state = thread_running
    reboot_state = thread_running
    do
    if int(rnd*10000)=0 then error 10000
    loop
    exit sub
   
    error_handler:
    print "ERRORHANDLER STARTED!"
    print "THREADS : ";THREADS
    ctrl.state = thread_crashed
    reboot_state = thread_crashed
    threads-=1
    PRINT "RESTARTING..";
    ctrl.reboot @instable_thread,reboot_state
    PRINT "END OF ERRORHANDLER!!"
end sub


instable_thread

sleep
Tourist Trap
Posts: 2762
Joined: Jun 02, 2015 16:24

Re: Programm is simply closeing but.. why??

Postby Tourist Trap » Dec 12, 2018 19:52

Hello,

can you show an output of what it does before it crashes?
mrminecrafttnt
Posts: 86
Joined: Feb 11, 2013 12:23

Re: Programm is simply closeing but.. why??

Postby mrminecrafttnt » Dec 12, 2018 20:15

Tourist Trap wrote:Hello,

can you show an output of what it does before it crashes?

Yep it is now stablilized to show what it does and where it fails.

Code: Select all

#define thread_uninitalized 0
#define thread_running 1
#define thread_crashed 2

type thread_controller
    state as uinteger
    declare sub reboot(t_adress as any ptr,byref state as uinteger)
end type

sub thread_controller.reboot(t_adress as any ptr,byref state as uinteger)
    PRINT "REBOOTING..";
    if state = thread_crashed then
        PRINT "EXECUTE..";
        sleep 100
        print t_adress
        sleep 100
        threadcreate t_adress
        sleep 100
        if state = thread_running then print "REBOOT SUCCESFULL" ELSE PRINT "SOMETHING IS WORONG."
        sleep 100
    else
        print "NO REASON TO REBOOT"
    end if
end sub



sub instable_thread
    PRINT "INSTABLE THREAD IS RUNNING NOW"
    static as integer threads
    static as integer reboot_state
    threads+=1
    on error goto error_handler
    dim as thread_controller ctrl
    ctrl.state = thread_running
    reboot_state = thread_running
    do
    if int(rnd*10000)=0 then PRINT "SEND ERROR" :  error 10000
    loop
    exit sub
   
    error_handler:
    print "ERRORHANDLER STARTED!"
    print "THREADS : ";THREADS
    ctrl.state = thread_crashed
    reboot_state = thread_crashed
    threads-=1
    PRINT "RESTARTING..";
    ctrl.reboot @instable_thread,reboot_state
    PRINT "END OF ERRORHANDLER!!"
end sub


instable_thread

sleep
fxm
Posts: 9124
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Programm is simply closeing but.. why??

Postby fxm » Dec 12, 2018 21:09

I do not know what you want to do but the biggest mistake is that a thread-sub must have an Any Ptr parameter (even if not used):
sub instable_thread (byval p as any ptr = 0)
D.J.Peters
Posts: 7810
Joined: May 28, 2005 3:28

Re: Programm is simply closeing but.. why??

Postby D.J.Peters » Dec 13, 2018 1:48

I fixed only the syntax of the code not the logic if there any ;-)

Joshy

Code: Select all

#define thread_uninitalized 0
#define thread_running 1
#define thread_crashed 2

type thread_proc as sub(byval param as any ptr)

type thread_controller
  state as uinteger
  declare sub reboot(byval proc as thread_proc, byref state as uinteger)
end type

sub thread_controller.reboot(byval proc as thread_proc,byref state as uinteger)
  PRINT "REBOOTING..";
  if state = thread_crashed then
    PRINT "EXECUTE..";
    threadcreate proc
    sleep 100
    if state = thread_running then print "REBOOT SUCCESFULL" ELSE PRINT "SOMETHING IS WORONG."
  else
    print "NO REASON TO REBOOT"
  end if
end sub

sub instable_thread(byval param as any ptr)
  static as integer threads
  static as integer reboot_state
  PRINT "INSTABLE THREAD IS RUNNING NOW"
  threads+=1
  on error goto error_handler
  dim as thread_controller ctrl
  ctrl.state = thread_running
  reboot_state = thread_running
  do
    if int(rnd*10000)=0 then error 10000
    sleep 10
  loop
  exit sub
   
error_handler:
  print "ERRORHANDLER STARTED!"
  print "THREADS : ";THREADS
  ctrl.state = thread_crashed
  reboot_state = thread_crashed
  threads-=1
  PRINT "RESTARTING..";
  ctrl.reboot @instable_thread,reboot_state
  PRINT "END OF ERRORHANDLER!!"
end sub


instable_thread(0)

sleep

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests