Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aainaj/8bc2a136403ee97ab2ce1cb544719a26 to your computer and use it in GitHub Desktop.
Save aainaj/8bc2a136403ee97ab2ce1cb544719a26 to your computer and use it in GitHub Desktop.
Featured Topics Concurrent Access Failure
func testFeaturedTopics() {
let count = 200
for index in 0..<count {
FeaturedTopics.shared[String(index)] = index
}
// The dispatch queue executes the submitted blocks in parallel and waits for all iterations to complete before returning
DispatchQueue.concurrentPerform(iterations: count) { (index) in
if let indexNumber = FeaturedTopics.shared[String(index)] as? Int {
print(indexNumber)
}
}
FeaturedTopics.shared.reset()
// Re-add the values concurrently
DispatchQueue.concurrentPerform(iterations: count) { (index) in
print("index \(index)")
FeaturedTopics.shared[String(index)] = index
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment