Skip to content

Instantly share code, notes, and snippets.

@LucianoPAlmeida
Last active April 21, 2018 23:08
Show Gist options
  • Save LucianoPAlmeida/95c94fe0f3fa36a82f606ed135bfdffc to your computer and use it in GitHub Desktop.
Save LucianoPAlmeida/95c94fe0f3fa36a82f606ed135bfdffc to your computer and use it in GitHub Desktop.
import Foundation
struct Node {
var childs: [String] = []
init() {}
mutating func clearChilds() {
if childs.isEmpty {
childs.removeAll()
}
}
}
var node = Node()
var lock = NSRecursiveLock()
DispatchQueue(label: "queue.test.exclusive-access").async {
lock.lock()
node.clearChilds()
lock.unlock()
}
DispatchQueue(label: "queue.test.exclusive-access.other").async {
lock.lock()
node.clearChilds()
lock.unlock()
}
print("Everything is OK now \\o/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment