The formal syntax of the Use...End use structure is:
Use(Shared_object_or_Shared_collection)
statement(s)
End use
The Use...End use structure defines a sequence of statements that will execute tasks on the Shared_object_or_Shared_collection parameter under the protection of an internal semaphore. Shared_object_or_Shared_collection can be any valid shared object or shared collection.
Shared objects and shared collections are designed to allow communication between processes, in particular, Preemptive 4D processes. They can be passed by reference as parameters from a process to another one. For detailed information on shared objects or shared collections, refer to the Shared objects and shared collections page. Surrounding modifications on shared objects or shared collections by the Use...End use keywords is mandatory to prevent concurrent access between processes.
- Once the Use line is successfully executed, all Shared_object_or_Shared_collection properties/elements are locked for all other process in write access until the corresponding End use line is executed.
- The statement(s) sequence can execute any modification on the Shared_object_or_Shared_collection properties/elements without risk of concurrent access.
- If another shared object or collection is added as a property of the Shared_object_or_Shared_collection parameter, they become connected within the same shared group (see Using shared objects or collections).
- If another process tries to access one of the Shared_object_or_Shared_collection properties or connected properties while a Use...End use sequence is being executed, it is automatically put on hold and waits until the current sequence is terminated.
- The End use line unlocks the Shared_object_or_Shared_collection properties and all objects sharing the same locking identifier.
- Several Use...End use structures can be nested in the 4D code. In that case, all locks are stacked and properties/elements will be released only when the last End use call is executed.
Note: If a collection method (see Collection methods) modifies a shared collection, an internal Use is automatically called for this shared collection while the function is executed.