Daily iOS
CS fundamentals and algorithms

Thread explosion

Running this code, which downloads 200 URLs with GCD, sends the system thread count past 60 and freezes the app. What's the most accurate cause?

for url in urls { // 200 URLs
    DispatchQueue.global().async {
        let sema = DispatchSemaphore(value: 0)
        download(url) { _ in sema.signal() }
        sema.wait()
        process()
    }
}

Pick one

Submit