Wednesday, March 11, 2015

Let’s Build @synchronized

Mike Ash:

Apple’s implementation of @synchronized is available as part of the Objective-C runtime source distribution. This specific bit is available here.

It’s build for speed rather than simplicity as the above toy implementation is. It’s interesting to see what it does the same and what it does differently.

The basic concept is the same. There’s a global table that maps object pointers to locks, and the lock is then locked and unlocked around the @synchronized block.

I love reading about Apple’s runtime optimization techniques.

Comments RSS · Twitter

Leave a Comment