Przemek, 
I can send you all the manual of xBase++. They have the best manual I've
ever read and over there you can find a lot of information's As an example :

SET DELETED on | OFF | <lToggle> 

Scope: thread-local, current work space


As for variables visibility :



Visibility of variables in different threads 

  Visibility              Storage class    

  Visible in the process  PUBLIC           
  (all threads)           STATIC           
                                           
  Visible in the thread   LOCAL            
  (this Thread)           PRIVATE          
                          FIELD            

Variables declared as LOCAL or PRIVATE are only visible in the thread where
the declaration occurred. The variables declared with PUBLIC or STATIC are
visible in all threads of a process (application program). Field variables
(FIELD) are visible in a work area of a work space. A work space is bound to
a thread. Since work spaces can be moved between threads, field variables
can become visible in different threads. At a given point in time, a field
variable is visible only in one thread. 

Whenever program code is divided up into different threads, the possibility
of multiple threads having simultaneous access to the same variable (PUBLIC
or STATIC) and changing it should be avoided. If multiple threads are
modifying the same variable, the value of the variable is not predictable.
The following example demonstrates this situation: 

   STATIC snNumber := 0                  // file-wide visible STATIC 
 
   PROCEDURE Main 
      LOCAL i, oThread := Thread():new() // create thread object 
 
      oThread:start( "Decrement" )       // decrement snNumber 
 
      FOR i:=1 TO 10000 
         snNumber ++                     // increment snNumber 
      NEXT 
 
      ? "Result:", snNumber              // theoretically this is 0 
   RETURN 
 
   PROCEDURE Decrement 
      LOCAL i 
      FOR i:=1 TO 10000 

         snNumber --                     // decrement snNumber 
      NEXT 

   RETURN 

In the example, two FOR...NEXT loops run simultaneously in two different
threads. The same STATIC variable is accessed in both threads. The first
thread increments the variable 10000 times and the second thread decrements
the variable 10000 times. Theoretically, the result would be the value zero.
In practice this value is seldom reached. Generally the value of snNumber at
the end of the program is greater than zero. This is because the operating
system independently allocates the processor time for the two threads. The
FOR...NEXT loop in the Main procedure begins incrementing as soon as the
first thread is started. Switching between the threads takes time, and the
STATIC variable increments several times before the second thread has
actually started. When the FOR...NEXT loop in the first thread ends, the
entire process is terminated, including the second thread. This means that
the FOR...NEXT loop in the second thread is cancelled before the counter
variable i reaches the value 10000. For this reason, the value of snNumber
at the end of the program is almost always greater than zero. 

This program demonstrates that programming multiple threads requires
consideration of special issues. Simultaneous access to the same variables
or files by multiple threads should be avoided. When two threads are using
the same variables, the result (or the value of the variable) is not
predictable, since the operating system allocates which thread is to receive
available processor time. The thread which last performed an assignment sets
the value of the variable. As a general rule, the part of the program that
is to run in a separate thread should be written in such way that it can be
compiled and linked as an independent program. All variables in a thread
should be protected from access by other threads.



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

Reply via email to