xHarbour Reference Documentation > Function Reference |
Retrieves the numeric application Thread ID of a thread.
GetThreadID( [<pThreadHandle>] ) --> nApplicationTID
The function returns the numeric ID of a thread as it is used by the xHarbour application.
Function GetThreadID() returns the numeric Thread ID (TID) as it is used by xHarbour's virtual machine. TIDs are unique and are generated sequentially. This guarantees the following conditions:
1. | the TID of the Main thread is always 1. |
2. | the TID of the next thread created is larger than the TID of a previously created thread. |
3. | if GetThreadID() returns the same TID for two <pThreadHandle>s, both <pThreadHandle>s refer to the same thread. |
Note: if <pThreadHandle> does not contain a valid thread handle, a runtime error is raised. Refer to function IsValidThread() to test the validity of a thread handle.
See also: | GetCurrentThread(), GetSystemThreadID(), HB_MutexCreate(), StartThread(), ThreadSleep() |
Category: | Multi-threading functions , xHarbour extensions |
Source: | vm\thread.c |
LIB: | xhbmt.lib |
DLL: | xhbmtdll.dll |
// The example displays the application TID and system TID of // ten threads. PROCEDURE Main LOCAL i, aTID := {} DisplayTIDs() FOR i:=1 TO 9 StartThread( "GetTIDs", aTID ) NEXT WaitForThreads() AEval( aTID, {|c| QOut(c) } ) RETURN PROCEDURE GetTIDs( aTID ) LOCAL th := GetCurrentThread() LOCAL cTID IF GetThreadID( th ) == 1 cTID := "Main thread : " ELSE cTID := "Child thread: " ENDIF cTID += " APP TID:" + Str( GetThreadID( th ), 5 ) cTID += " SYS TID:" + Str( GetSystemThreadID( th ), 5 ) AAdd( aTID, cTID ) RETURN
http://www.xHarbour.com