4 ms·
$ swiftc - import Dispatch var array = [Int]() DispatchQueue.global().async { while true { array.append(Int.random(in: .min...(.max)
by saagarjha 4y ago
$ swiftc -
import Dispatch
var array = [Int]()
DispatchQueue.global().async {
while true {
array.append(Int.random(in: .min...(.max)))
}
}
DispatchQueue.global().async {
while true {
let range = 0..<array.count
guard !range.isEmpty else {
continue
}
array.remove(at: Int.random(in: range))
}
}
dispatchMain()
$ ./main
Segmentation fault: 11
$ ./main
main(71894,0x16f103000) malloc: double free for ptr 0x13e808200
main(71894,0x16f103000) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6
$
- lalaithion 4y agoThanks!