• 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: NSDictionary @synchronize to read multiple objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary @synchronize to read multiple objects


  • Subject: Re: NSDictionary @synchronize to read multiple objects
  • From: Roland King <email@hidden>
  • Date: Thu, 10 Apr 2014 18:29:31 +0800

On 10 Apr, 2014, at 6:20 pm, Dave <email@hidden> wrote:

> Hi,
>
> I was confused by this:
>
>> It also doesn't make sense to synchronize on the myDict object.  That's what is in flux.  You should synchronize on "self", the object which owns and manages myDict.
>
> Surely as long as every access to the dictionary is @synchronized to the same entity it’s fine?
>
> The way I’d atcheive this is to make the NSMutableDictionary a private property:
>
> @property (nonatomic,strong)    NSMutableDictionary*      pDictX;
>
> and define public methods:
>
> -(void) removeObjectFromDictXWithKey:(NSString*) theKey;
> -(void) addObject:(id) theObject toDictXWithKey:(NSString*) theKey;
> -(id) getObectFromDictXWithKey:(NSString*) theKey;


Yes but that's not what he's doing, he's not mutating the dictionary (even though it's mutable), he's replacing one dictionary with another one. So the point of synchronizing on self in that case is to prevent the dictionary being swapped out between calls.


>
>>>
>>>> On Mar 31, 2014, at 10:16 PM, Trygve Inda <email@hidden> wrote:
>>>>
>>>>> I need to be able to set a new myDict and not have it happen between the
>>>>> reading of different values from the dictionary by other threads.
>>>>

_______________________________________________

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: NSDictionary @synchronize to read multiple objects
      • From: Ken Thomases <email@hidden>
References: 
 >Re: NSDictionary @synchronize to read multiple objects (From: Trygve Inda <email@hidden>)
 >Re: NSDictionary @synchronize to read multiple objects (From: Dave <email@hidden>)

  • Prev by Date: Re: NSButton/NSBox interaction
  • Next by Date: NSTask: program launching another program, potential problem with path: how to do?
  • Previous by thread: Re: NSDictionary @synchronize to read multiple objects
  • Next by thread: Re: NSDictionary @synchronize to read multiple objects
  • Index(es):
    • Date
    • Thread