russell
russell

Reputation: 3766

Atomic property block or cancel a particular thread request for accessing variable when variable is already used by another thread

Suppose there is a string named - aString

@property (atomic, retain) NSString *aString;

So now suppose Thread A is working with aString, at that time Thread B is trying to access aString. I know since aString property is atomic, Thread B won't be able to access it but my question is whether Thread B's access request is cancelled or it's request will execute after Thread A finish it's execution.

Thanks for you reply.

Upvotes: 1

Views: 217

Answers (1)

Manu
Manu

Reputation: 788

Thread B will wait untill thread A finished to read the property content.

When you access a property is nothing else that call the getter method of the property, and if is atomic means that the getter method access is protected by a mutex, so untill the getter method doesn't return all the other thread trying to access the property are waiting.

If you owerwrite the getter/setter of the property you are responsable to implement the thread synchronization into the methods body otherwise the property will be no longer atomic

Upvotes: 1

Related Questions