Shared collection and shared objects always require a Use…end use to enclose any modification; however, for convenience, 4D automatically triggers an internal Use...end use on collection functions such as: push(), clear(), reverse(), etc..
Therefore, no explicit Use...end use is needed for the following:
|$sharedCol:=New shared collection|
$sharedCol2:=New shared collection("one"; "two")
This built-in Use...end use is also triggered with read-only access to a property of a shared collection.
An explicit Use...end use must be used if there is any direct modification of element.
$sharedCol:=9 // this will cause an error
For each operation on a shared object you are blocking access during that atomic function. A Use…end use may be beneficial if you want several modification to be performed atomically:
$sharedCol:=4 // No error
Enclosing several modifications with one single Use...end use might have a performance benefit, because you only have a single lock/unlock pair, as opposed to several. The downside is if it takes the lock longer, then another process that is willing to update the same collection may have to wait longer.