Statement SYNC Foundation
Declares a method which is synchronized across any number of threads
SYNC [CLASS] METHOD <MethodName>
When an object is visible in multiple threads at the same time, the SYNC attribute makes sure that the program code of a method is executed entirely in one thread before another SYNC method of the same object can be executed in another thread. SYNC methods are automatically synchronized when executed by different threads. Therefore, when different SYNC methods are called for the same object (self) from multiple threads, they are executed in sequential order without being interrupted. Only one SYNC method can be executed using the same object (self) at any given point in time.
In multi-threaded programs, the SYNC attribute is necessary when a method performs multiple operations to achieve a consistent state of an object (self). This is the case, for example, when multiple instance variables are changed within a method and the object's consistency depends on all changes to be completed before the method is executed in another thread. The SYNC attribute guarantees that the program code of a method will run to completion within a single thread. No other thread can execute a SYNC method with the same object before the method has returned.
SYNC methods and Signals
There is one exception to the above stated rule. If thread A has suspended program execution of a SYNC method due to waiting for a signal, another SYNC method of the same object can be invoked in thread B. The suspended thread A will resume with method execution after being signalled only when the second SYNC method has run to completion in thread B (see the second example below).
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.