There are three types of synchronization calls:
●synchronize (activity_address);
The activity address is the address of the activity status variable defined in the package where the activity is referenced.
● Ada DELAY statementEach one of these calls suspends the activity and reschedule another activity or the
main_task
(statechart) on a round-robin policy.The
wait_for_event
call suspends the activity until the specified event is generated. It is a way to synchronize the activity with other activities (either user-implemented or statechart controlled). When the event is generated, the code resumes execution after the wait call.wait_for_event (start’address);
The Ada DELAY statement delays the activity for the time specified in the call. It is useful to implement polling processes that periodically perform checks on a time basis.
mouse_input := get_input_from_mouse ;
if mouse_input /= null . . . . .
Note: The DELAY statement allows other activities to run, but stop and suspend do not take effect. If you wish to stop or suspend the activity by other activities, add a synchronize call after theDELAY
statement.The
activity_synchronize
is used when you have a lengthy calculation which is too long to be executed without interruption. For example, if you have to multiply two 10000x10000 matrices, you do not want the rest of the system to be blocked all that time. Theactivity_synchronize
call allows other activities to proceed, and the calling activity resumes execution in the next available time slot unless a stop or suspend command is issued. The call should be placed in a loop in which one cycle can be executed without preemption, but an outer loop may take too long.-- the internal loop is short enough to -- complete.