Classes

Method Thread():synchronize() Foundation

Synchronizes a second thread with the current thread.

Syntax
:synchronize( <nTimeOut> ) --> lSuccess
Parameters
<nTimeOut>
<nTimeOut> is a positive integer specifying a time interval in increments of 1/100ths of a second. The current thread waits until this interval has elapsed. The second thread is managed by the Thread object executing the method :synchronize(), i.e. the thread where :synchronize() is called waits for the Thread object which executes this method. When the value zero is specified for <nTimeOut>, the current thread waits indefinitely until the code in the other thread is complete.
Return

When the program code of a second thread has completed its processing following :synchronize(), the method returns the value .T. (true). If the return value is .F. (false), the process in the other thread could not be completed within the specified time interval.

Description

The method :synchronize() allows the current thread to be synchronized with other threads. The current thread waits for termination of the execution of a thread managed by a Thread object. Generally, this method is only needed when threads whose results are dependent on each other are run within an Xbase++ application. For example, part of a statistic might be calculated in thread A while another part of the same statistic is calculated in thread B. Before the complete result can be displayed, both threads must be finished so that thread A can take the entire result into consideration. If thread B needs more time for calculation than thread A, thread A may need to wait for thread B. In this case, the message :synchronize() would be sent to the Thread object managing thread B within thread A.

When the current thread must wait for the end of a second thread, there are two possible approaches:

DO WHILE .NOT. oThreadB:synchronize(1) 
   <programm code> 
ENDDO 

/* or */ 

oThreadB:synchronize(0) 

Both approaches cause the program in the current thread to be continued only after thread B has finished. The first possibility uses a loop that is exited only when the second thread has ended. In the second case, the current thread is stopped until thread B terminates. During this period, processor time is allocated only to thread B. The current thread resumes when thread B has terminated.

Before calling :synchronize(), make sure that no time interval is defined with :setInterval(). If an interval is set, the :synchronize() method may never return.

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.