Is Objective-C's NSMutableArray thread-safe?

前端 未结 7 929
野的像风
野的像风 2020-12-04 09:54

I\'ve been trying to fix this crash for almost a week. The application crashes without any exception or stack-trace. The application does not crash in any way while running

相关标签:
7条回答
  • 2020-12-04 10:52

    Since serial queues were mentioned: With a mutable array, just asking "is it thread safe" isn't enough. For example, making sure that removeAllObjects doesn't crash is all good and fine, but if another thread tries to process the array at the same time, it will either process the array before or after all elements are removed, and you really have to think what the behaviour should be.

    Creating one class + object that is responsible for this array, creating a serial queue for it, and doing all operations through the class on that serial queue is the easiest way to get things right without making your brain hurt through synchronisation problems.

    0 讨论(0)
提交回复
热议问题