xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

IsValidThread()

Checks if an expression is the thread handle of a running thread.

Syntax

IsValidThread( <xValue> ) --> lIsValid

Arguments

<xValue>
This is a value of any data type.

Return

The function returns .T. (true) when <xValue> is the thread handle of a running thread, otherwise .F. (false) is returned.

Description

Function IsValidThread() is used to detect if the passed parameter is a handle to a valid thread. A thread is valid when it is successfully started and has not ended, yet. Thus, IsValidThread() can be used to detect if a thread is "running". It cannot detect, however, if a thread is actually executing program code since "sleeping" or suspended threads waiting for Mutexes are valid, but are put "on hold".

Info

See also:GetCurrentThread(), GetThreadID(), IsSameThread(), StartThread(), ThreadSleep()
Category: Multi-threading functions , xHarbour extensions
Source:vm\thread.c
LIB:xhbmt.lib
DLL:xhbmtdll.dll

Example

// The example demonstrates that IsValidThread() returns only
// True when a handle to a started thread is passed.

   PROCEDURE Main
      LOCAL pThread

      ? IsValidThread( pThread )         // result: .F.

      pThread:= StartThread( "RunInThread" )

      ? IsValidThread( pThread )         // result: .T.

      JoinThread( pThread )

      ? IsValidThread( pThread )         // result: .F.
  RETURN


  PROCEDURE RunInThread()
     ? "Thread started:", GetThreadID()

     ThreadSleep( 500 )
  RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe