Attempt to fix resurrection of dead objects in KVO signals

In order for a KVO signal to complete immediately after the object has deallocated (and never crash), we basically need to temporarily stave off deallocation if the KVO observation is currently setting up. The only way I could imagine to do that is an explicit lock.

So, this hopefully fixes #1016. I'm not entirely convinced of the theoretical correctness, but I was at least unable to reproduce it on my machine (where the added test consistently fails before).

@epatey