Is this thread safe?
Posted: Sat Apr 12, 2025 9:59 pm
I modified the sample code to have the tread kill itself. Is that a bad thing?
I am considering use of threads, but I want the thread to die after it completes it's task.
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - Thread example file
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
Global thread
Procedure AlertThread(Parameter)
Repeat
Debug "Alert ! "+Str(Parameter)
Delay(3000)
Parameter-1
If Parameter = 147
KillThread(thread)
EndIf
ForEver
EndProcedure
thread = CreateThread(@AlertThread(), 154)
; MessageRequester("Info", "It will display an alert every 3 seconds."+#LF$+"Click To kill the alerts", 0)
; KillThread(thread)
MessageRequester("Info", "Click To finish the program", 0)