Function ThreadInfo() Foundation

Retrieves information about existing threads.

Syntax
ThreadInfo( <nWhichInfo>, [<nThreadID>] ) --> aInfo
Parameters
<nWhichInfo>
#define constants from the file THREAD.CH must be used for this parameter. They determine the type of information returned by the function. Multiple constants can be combined with '+'.
Constants for ThreadInfo()
Sequence Constant Description
A THREADINFO_TID The numeric thread ID
B THREADINFO_SYSTHND The numeric handle used by the operating system for this thread.
C THREADINFO_FUNCINFO The function name and line number currently being executed.
D THREADINFO_TOBJ The thread object representing the thread
<nThreadID>
An optional thread ID can be passed to obtain information about one particular thread. If this parameter is omitted, all threads are queried.
Return

The function returns a two-dimensional array where each thread has one sub-array containing one or more elements controlled by <nWhichInfo>. If <nWhichInfo> is a combination of constants, the elements of the sub-array (the array columns) appear in the sequence order of each constant (first column in the table).

Description

The function ThreadInfo() returns various information about existing threads of the current process. The constant THREADINFO_TID retrieves the Xbase++ thread ID which is also returned by the ThreadId() function for the current thread. THREADINFO_SYSTHND retrieves the thread IDs used by the operating system. They are provided for calling API functions or for passing system IDs to third-party tools which require this low-lovel information. THREADINFO_FUNCINFO results in two elements being added to the sub-arrays. They contain program line and name of the function or method currently being executed in the corresponding thread. Both elements contain NIL if the thread is idle and does not process program code. THREADINFO_TOBJ finally retrieves the Thread object representing a thread.

Examples
Obtaining information about threads
// The example lists full and partial information 
// about threads that can be retrieved with ThreadInfo() 

#include "Thread.ch" 

PROCEDURE Main 
   LOCAL aInfo, aThread := { Thread():new(), Thread():new() } 

   CLS 
   aThread[1]:start( "Test1" ) 
   aThread[2]:start( "Test2" ) 

   ? "Retrieve all thread information" 
   aInfo := ThreadInfo( THREADINFO_TID      + ; 
                        THREADINFO_SYSTHND  + ; 
                        THREADINFO_FUNCINFO + ; 
                        THREADINFO_TOBJ       ) 

   AEval( aInfo, {|a| QOut( Var2Char(a) ) } ) 

   ? 
   ? "Retrieve partial thread information" 
   aInfo := ThreadInfo( THREADINFO_FUNCINFO + ; 
                        THREADINFO_TID        ) 

   ? 
   AEval( aInfo, {|a| QOut( Var2Char(a) ) } ) 
RETURN 


PROCEDURE Test1 
   DO WHILE .T. 
      DispOutAt( 10, 10, Time() ) 
      Sleep(100) 
   ENDDO 
RETURN 


PROCEDURE Test2 
   LOCAL nCount := 0 
   DO WHILE .T. 
      DispOutAt( 12, 10, nCount ++ ) 
      Sleep(17) 
   ENDDO 
RETURN 

// Program output 

// Retrieve all thread information 
// {1, 324, 14, MAIN, thread} 
// {2, 724, 31, TEST1, thread} 
// {3, 748, 40, TEST2, thread} 
// 
// Retrieve partial thread information 
// {1, 21, MAIN} 
// {2, 31, TEST1} 
// {3, 40, TEST2} 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.