objective c - Is it safe to insert multiple different key-value pairs to an NSMutableDictionary simultaneously? -
if have multiple threads might want write nsmutabledictionary
(i.e. setobject:forkey:
) simultaneously, need synchronize on dictionary if can guarantee threads writing different key-value pairs? if yes, can explain how dictionary break?
nsmutabledictionary
not thread-safe, need add together synchronization around concurrent writes, around reads might proceed concurrently writes. fact writing different keys not help much: implementation may resize on adding new key, invalidating internal storage has been allocated before.
you may lucky if keys planning write exist in dictionary already, , no concurrent removals going on. however, strongly recommend against approach.
objective-c thread-safety
No comments:
Post a Comment