Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is objc_sync_exit(self)

Tags:

swift

I saw this function being used in a UISearchBarDelegate method textDidChange. I looked all over for any documentation and couldn't come up with anything. Just wondering if anyone could shed any light on what this function is doing.

 objc_sync_exit(self)
like image 661
technoY2K Avatar asked Oct 31 '22 13:10

technoY2K


1 Answers

When you write synchronized code to stop something being run more than once at a time (Objective-C: "@synchronized"), that gets transformed into calls to objc_sync_enter() and objc_sync_exit() calls behind the scenes.

If you saw someone using these functions directly, it would suggest that they couldn't use the plain old synchronized block (or their own Swift wrapper for it) because their code is split up somehow - synchronization starts and ends in different places.

Here's a nice Swift implementation that wraps this code similarly to Objective-C.

like image 161
TwoStraws Avatar answered Nov 08 '22 06:11

TwoStraws