views:

46

answers:

1

It's fairly well documented that @synthesize atomic settings/getters are implemented with "something" like so:

{
    [_internal lock]; // lock using an object-level lock
    id result = [[value retain] autorelease];
    [_internal unlock];
    return result;
}

The situation I have, I want to access two properties atomically (ie. not unlocking the lock inbetween), so my first instinct was to use @synchronized(self) - however I've been unable to find anything that says if @synchronized(self) uses the same lock as an atomic getter/setter. Does anyone know if they do?

+2  A: 

One of the things Apple's docs are very good at, is specifying exactly what the contract is. In this case, the relevant part of the docs says only that it's locked using an object-level lock. Note that it doesn't say which lock it is, so you cannot assume it's the same locking mechanism as @synchronized(self). (It may very well be not.)

millenomi
Although that doesn't actually answer my question, it is a very polite way of pointing out that I'm asking the wrong question. As you say, what matters is whether I can rely on them being the same thing as Apple upgrades the OS, regardless of whether or not they're currently the same thing. Thanks!
JosephH