• 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
Thread safety
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Thread safety
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Opening a saved project
  • Next by Date: Remote host reachability
  • Previous by thread: Re: Opening a saved project
  • Next by thread: Re: Thread safety
  • Index(es):
    • Date
    • Thread