Avoid copying NSMutableArray for reading with multithreaded writes

前端 未结 3 1315
囚心锁ツ
囚心锁ツ 2020-12-19 12:04

I have a class that uses a mutable array that is modified once after a lot of reads (new items arrive).

The problem is that when times comes to mutate the array, rea

3条回答
  •  梦毁少年i
    2020-12-19 12:31

    in this case, you would consider using a read/write lock. Cocoa doesn't provide them, but pthread_rwlock_t is available in pthreads interfaces -- declared in pthread.h. note that this is going to be much more efficient (for your usage) than @synchronized, or even a plain lock.

提交回复
热议问题