Created
September 13, 2012 09:39
-
-
Save steipete/3713233 to your computer and use it in GitHub Desktop.
I often use dispatch queues for locking, and this function just makes life SO MUCH EASIER. Accidental deadlocks in more complex code paths are a PITA otherwise. But Apple deprecated dispatch_get_current_queue with iOS6?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nline void pspdf_dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_block_t block) { | |
dispatch_get_current_queue() == queue ? block() : dispatch_sync(queue, block); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ctp I agree that it's part of the contract, and does violate ordering, but, in my opinion, such issues are preferable to deadlocks. All of these problems are difficult to verify statically (with a compiler or as a human), so it's really a question of which failure you would rather have.
I could see an argument either way, honestly, which sounds to me like it should be up to the caller. GCD is already a fairly low-level API – I think allowing users to make decisions like this fits with its design.