If I set up kvo observers on my main thread, but then on a background thread i change the value of the property being observed, does my main thread get interrupted immediately, no matter where it was?
Thanks!
"If I set up kvo observers on my main thread..."
It is irrelevant what thread you used to set up a KVO observer. The KVO observer will be called back on the thread where the value was changed.
I can't stress this enough - KVO does not manage thread-safety for you!
The Receptionist Pattern is designed to solve this problem.
https://developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/ReceptionistPattern/ReceptionistPattern.html
Do not try and simply switch threads using GCD in observeValueForKeyPath:ofObject:change:context: without an intermediary object, or you will likely end up with a race condition against dealloc (see the "Deallocation Problem" - https://developer.apple.com/library/ios/technotes/tn2109/_index.html#//apple_ref/doc/uid/DTS40010274-CH1-SUBSECTION11 )
No your main thread will not get interrupted, just like the case of the question you posted 2 minutes ago.
The only way a thread will really be interrupted, is when the program would receive a signal. This generally only happens if things go really wrong. (SIGSEGV, SIGABRT, etc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With