KillThread()

语法

KillThread(Thread)
概要
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.

参数

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

返回值

无.

示例

  ; 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

已支持操作系统

所有

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