Skip to content

Instantly share code, notes, and snippets.

@zyuanming
Created June 5, 2017 13:53
Show Gist options
  • Select an option

  • Save zyuanming/dae2aced0b1d5da080a8e017f1cfc1bb to your computer and use it in GitHub Desktop.

Select an option

Save zyuanming/dae2aced0b1d5da080a8e017f1cfc1bb to your computer and use it in GitHub Desktop.
Locks
internal final class SpinLock {
private let lock = NSLock()
func sync<T>(action: () -> T) -> T {
lock.lock()
defer { lock.unlock() }
return action()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment