Created
April 20, 2016 07:44
-
-
Save jmcd/b54b963fcec4ec981eb493e0e216c721 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Foundation | |
class ObjectWithCriticalResource: NSObject { | |
private let semaphore = dispatch_semaphore_create(1) | |
func doTask() { | |
guard dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) == 0 else { | |
// abort this call without doing the task | |
return | |
} | |
self.doTaskImpl() | |
} | |
private func doTaskImpl() { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment