Thread safety
Thread safety
- Subject: Thread safety
- From: Trygve Inda <email@hidden>
- Date: Tue, 28 Apr 2009 14:32:04 +0000
- Thread-topic: Thread safety
The docs say that:
"Note that although NSSerializer, NSArchiver, NSCoder, and NSEnumerator
objects are themselves thread-safe, they are listed here because it is not
safe to change the data objects wrapped by them while they are in use. For
example, in the case of an archiver, it is not safe to change the object
graph being archived. For an enumerator, it is not safe for any thread to
change the enumerated collection."
NSUnarchiver is not listed, but based on the above is the following ok?
NSArray* localArray;
localArray = [NSUnarchiver unarchiveObjectWithData:localData];
if (localArray)
{
NSEnumerator* enumerator = [localArray objectEnumerator];
NSDictionary* dict;
while (dict = [enumerator nextObject])
{
if ([[dict objectForKey:@"myVal"] unsignedShortValue] == kSomeValue)
{
// do things that are thread safe
}
}
}
Everything above is read only, so I don't think I am changing "data objects
wrapped by them while they are in use". Certainly this is true for
NSEnumerator, but not sure about the unwritten safety of NSUnarchiver.
The code is working in a thread, and has not crashed.
Trygve
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden