Last active
April 21, 2018 23:09
-
-
Save LucianoPAlmeida/dc07f8a877ffcfc80035cd79947b51a6 to your computer and use it in GitHub Desktop.
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
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