• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Thread safety
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Thread safety (From: Trygve Inda <email@hidden>)

  • Prev by Date: Remote host reachability
  • Next by Date: Re: C string constant->NSString constant without defining twice?
  • Previous by thread: Thread safety
  • Next by thread: Remote host reachability
  • Index(es):
    • Date
    • Thread