xHarbour Reference Documentation > Function Reference |
Checks if an expression is the thread handle of a running thread.
IsValidThread( <xValue> ) --> lIsValid
The function returns .T. (true) when <xValue> is the thread handle of a running thread, otherwise .F. (false) is returned.
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".
See also: | GetCurrentThread(), GetThreadID(), IsSameThread(), StartThread(), ThreadSleep() |
Category: | Multi-threading functions , xHarbour extensions |
Source: | vm\thread.c |
LIB: | xhbmt.lib |
DLL: | xhbmtdll.dll |
// 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
http://www.xHarbour.com