Last active
April 21, 2018 23:08
-
-
Save LucianoPAlmeida/95c94fe0f3fa36a82f606ed135bfdffc 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] = [] | |
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