gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
426 stars 116 forks source link

Potential atomic property/init deadlock fix #285

Open ERobsham opened 4 months ago

ERobsham commented 4 months ago

Initial attempt at resolving issue #284 (Rare atomic property during initialization deadlock)

davidchisnall commented 4 months ago

I think this code looks correct, it would be nice to have a test. I’m still not quite sure how code can get to this path though.

ERobsham commented 4 months ago

That is a tough one. I'm not really sure how to force this behavior, as its been very intermittent in our systems. There are definitely a couple of exacerbating factors I know of:

The process that is deadlocking for us has the 'main application' class with a ton of atomic properties, and most of those classes are also host to a bunch of atomic properties, in some cases this continues a number of levels deep...

As far as I can tell the only way to hit this is more or less a numbers game. You need to have an instance of an object where it has an atomic property, and both theAtomicProp and theAtomicProp.class->isa produce the same hash when run through the lock_for_pointer() hashing -- And the class for the atomic property needs to currently have an uninstalled dtable when you try to 'get' the property for the first time.