Skip to content

Instantly share code, notes, and snippets.

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