Can anybody give me example that NSMutableArray is thread safe or not?
Asked
Active
Viewed 6,692 times
8
-
possible duplicate of [Thread-safe NSMutableArray question](http://stackoverflow.com/questions/1703294/thread-safe-nsmutablearray-question) – Filip Ekberg Feb 16 '11 at 13:46
-
possible duplicate of [Synchronizing NSMutableArray for Thread Security](http://stackoverflow.com/questions/3521190/synchronizing-nsmutablearray-for-thread-security) – Abizern Feb 16 '11 at 13:47
2 Answers
6
According to the Apple docs NSMutableArray is not thread safe.
Mutable objects are generally not thread-safe. To use mutable objects in a threaded application, the application must synchronize access to them using locks. (For more information, see “Atomic Operations”). In general, the collection classes (for example, NSMutableArray, NSMutableDictionary) are not thread-safe when mutations are concerned. That is, if one or more threads are changing the same array, problems can occur. You must lock around spots where reads and writes occur to assure thread safety.

SamG
- 646
- 4
- 8