KillThread()

Syntax

KillThread(Thread)
Description
Imediately kills the specified thread, which had previously been created with CreateThread(). This is a very dangerous function, and should only be used rarely. The problem is that the thread is killed immediately and has no chance to perform any cleanup code (for example, freeing memory, releasing items, de-allocating its own stack).

If possible, a flag like a global variable should be used to tell the thread to quit itself (which does the needed cleanup) and this command should only be used if this is not possible for some reason.

Parameters

Thread - The number of the thread that you want to kill. This value is returned by CreateThread().

Example:

  ; A procedure/thread which will never exit. Not good, but it
  ; shows how KillThread works 
  Procedure PrintStuff(interval)
    Repeat
      PrintN(".")
      Delay(interval)
    ForEver
  EndProcedure
  
  If OpenConsole()
    thread = CreateThread(@PrintStuff(), 500)
    If thread
      For i=0 To 10
        PrintN("A")
        Delay(999)
  
        If i=5
          KillThread(thread)
        EndIf
      Next
    EndIf
  EndIf

Supported OS

All

<- IsThread() - Thread Index - LockMutex() ->