KillThread()

Syntax

KillThread(Thread)
Description
Immediately 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 function should only be used if this is not possible for some reason.

Parameters

Thread The thread to kill. This value is returned by CreateThread().

Return value

None.

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() ->