0
@frozen public struct Array<Element> {

This is the declaration of Array in swift. struct in swift is thread-safety, Array is struct, why Array is not thread-safety?

First, I declare a struct.

struct MyStruct {
    var testArray: [Int] = [1]
}

Then, I write a concurrent test, It crashed when running

var test = MyStruct ()
DispatchQueue.concurrentPerform(iterations: 500) { index in
    test.testArray.append (100) //Thread 14: EXC_BAD_ACCESS (code=1, a...
}
2
  • 1
    Possibly helpful: stackoverflow.com/q/75459511/1187415 Commented Oct 9, 2024 at 7:32
  • 3
    "struct in swift is thread-safety" is generally not true. Where did you read that from? Commented Oct 9, 2024 at 7:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.