You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of RSAtomic does not guarantee atomicity. This is because of a couple reasons:
it is implemented as a struct property wrapper, which could incur additional copies of the internal state of the atomic wrapper, breaking atomicity.
hiding the load and store operations in a getter/setter allows obvious race conditions like value += 1 that will expanded to two separate load and store operations, while it should be implemented as a CAS.
import Foundation
varatomicCounter=RSAtomic(wrappedValue:0)DispatchQueue.concurrentPerform(iterations:1000){ _ in
atomicCounter.value +=1}print(atomicCounter.value)
The result will most often be less than 1000, like in this screenshot:
You should either use DispatchQueues, or actors, or the official Swift Atomics package instead.
Expected behavior RSAtomic should be atomic.
Version of the iOS SDK
Swift SDK 1.26.2, latest.
SDK initialisation snippet
Irrelevant.
Check for Correct Usage of writeKey and dataPlaneUrl
Irrelevant.
The text was updated successfully, but these errors were encountered:
Describe the bug
The current implementation of RSAtomic does not guarantee atomicity. This is because of a couple reasons:
struct
property wrapper, which could incur additional copies of the internal state of the atomic wrapper, breaking atomicity.value += 1
that will expanded to two separate load and store operations, while it should be implemented as a CAS.More in-detail explanation here: swiftlang/swift-evolution#1387
To Reproduce
Try this in a playground:
The result will most often be less than 1000, like in this screenshot:
You should either use
DispatchQueue
s, oractor
s, or the official Swift Atomics package instead.Expected behavior
RSAtomic
should be atomic.Version of the iOS SDK
Swift SDK 1.26.2, latest.
SDK initialisation snippet
Irrelevant.
Check for Correct Usage of writeKey and dataPlaneUrl
Irrelevant.
The text was updated successfully, but these errors were encountered: