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.. :/
#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
#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
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)
#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