Re: Key-Value Binding and Threads
Re: Key-Value Binding and Threads
- Subject: Re: Key-Value Binding and Threads
- From: Chris Kane <email@hidden>
- Date: Fri, 30 Mar 2007 09:18:49 -0700
On Mar 26, 2007, at 9:10 PM, King Chung Huang wrote:
Before everyone groans: No, I'm not asking if KVB is "thread-safe".
Searching on CocoaBuilder, the consensus seems to be that KVB is
not "thread-safe" in terms of mutating a key on a thread other than
the main thread and expecting UI changes to occur correctly. Would
I be correct in deducing that KVO/KVB change notifications are
processed on the thread where willChangeValueForKey: etc. is
implicitly or explicitly called? i.e., if I mutate an observed
value on thread B, then observers will be notified on thread B? Can
I safely observe a key on object A from object B, if both objects
are safe to mutate on the same thread?
I believe it is safe to say that the KVO notification will be
delivered on the thread on which the mutation (and will/
didChangeValueForKey: around it) occurs. The KVO notifications are
simply immediately delivered, synchronously. Same as with
NSNotifications.
This assumption would break if we ever changed things to
automatically shunt the KVO notification delivery to another thread
(say, the main thread). But I don't think we should ever do that,
and instead leave it to the developer to do that if they need to.
Or, do that up at higher levels, not at the low KVO level.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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