Hello Everybody

Just for information sake:


ThreadID() -> nThreadID 
----------
Return 

The function returns a numeric value > 0. 

Description 

The function ThreadID() is used to get the numeric ID of the thread in which
the function is called. The value is unique within a single process and may
occur multiple times in different processes. 


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. 

Example 

// 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} 


ThreadObject() --> oThread 
--------------
Return 

The function returns the Thread object which currently executes program
code. 

Description 

The function ThreadObject() is used to retrieve the current Thread object
when multiple threads are running. This is especially useful if the same
user-defined function is executed multiple times and simultaneously in
different threads. The function can also be used to retrieve the implicit
Thread object which executes the Main procedure at program startup. 


ThreadWait( <aThreads> , [<nTimeOut>], ) --> oThread | NIL 
-----------------------------------------
Parameters 

<aThreads>

<aThreads> is an array whose elements contain Thread objects. The current
thread waits for the termination of one or all of the corresponding threads.
The number of elements in <aThreads> is limited to the value of the constant
THREAD_WAIT_MAX from THREAD.CH. 

<nTimeOut>

<nTimeOut> specifies the maximum amount of time the current thread will wait
for the termination of other threads. The unit is 1/100th of a second. The
default value is 0 and this causes the current thread to wait infinitely
until one Thread object in <aThreads> has finished with executing code. If a
value > 0 is specified for <nTimeOut> and no thread has terminated within
this period of time, the current thread resumes progam execution. 

Return 

If one thread terminates within the time limit defined with <nTimeOut> , the
function returns the corresponding Thread object. Otherwise, the return
value is NIL. 

Description 

The function ThreadWait() causes the current thread to wait until one thread
from a number of threads has terminated. Compared to the :synchronize() 
method of the Thread class, the function has the advantage that the current
thread does not need to wait for a particular thread, but rather can wait
for any thread from a number of threads. Note that the number of threads the
current thread can wait for is limited to the constant THREAD_WAIT_MAX by
the operating system. 


ThreadWaitAll( <aThreads> , [<nTimeOut>]  ) --> lSuccess 
-------------------------------------------
Parameters 

<aThreads>

<aThreads> is an array whose elements contain Thread objects. The current
thread waits for the termination of all of the corresponding threads. The
number of elements in <aThreads> , or thread objects, respectively, is
limited to the value of the constant THREAD_WAIT_MAX from THREAD.CH. 

<nTimeOut>

<nTimeOut> specifies the maximum amount of time the current thread will wait
for the termination of all other threads. The unit is 1/100th of a second. 
The default value is 0 and this causes the current thread to wait infinitely
until all other Thread objects are finished with executing code. If a value
> 0 is specified for <nTimeOut> and no thread has terminated within this
period of time, the current thread resumes progam execution. 

Return 

When all threads specified in <aThreads> have terminated, the return value
is .T. (true). If the waiting period is limited by a value greater than 0
for <nTimeOut> and not all threads have terminated when this time limit has
expired, the function returns .F. (false). 

Description 

The function ThreadWaitAll() causes the current thread to wait for the
termination of multiple other threads. Compared to the :synchronize() method
of the Thread class, it has the advantage that the current thread does not
need to wait for one particular Thread object but rather can wait for
multiple threads to complete execution of code. 


Regards
Pritpal Bedi



-- 
View this message in context: 
http://www.nabble.com/MT---Thread-Specific-Functions-in-Xbase%2B%2B-tp19524300p19524300.html
Sent from the Harbour - Dev mailing list archive at Nabble.com.

_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to