-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Issue
In its current implementation, @OTAtomicsThreadSafe
is designed to work as a wrapper around variables installed in an object (class, struct, enum, etc.).
However it will strangely result in a data race when used on a variable declaration within a function. So this wrapper should not be used in this fashion.
The following code will almost always return a value that is less than 100:
Proposal
It is poor form to declare a local variable within a function and then attempt to mutate it concurrently. Better form is to take the value and pass it into a concurrent operation that can run synchronously within the method, then rely on the operation to return the fully mutated value, often by way of a completion handler closure which can be waited on.
It is not clear if there is a way to prevent the property wrapper from being used on variable declarations inside a method, as the compiler will not stop you from doing it.