Re: Thread safety
Re: Thread safety
- Subject: Re: Thread safety
- From: Keary Suska <email@hidden>
- Date: Tue, 28 Apr 2009 08:57:52 -0600
On Apr 28, 2009, at 8:32 AM, Trygve Inda wrote:
"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?
NSUnarchiver is not susceptible to the specific thread safety issue
mentioned in that doc note.
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.
As long as localData is completely thread safe, you won't have any
problems. The NSEnumerator doesn't enter into it, since localArray and
its contained objects exist only in the specific thread.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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