Skip to content

Instantly share code, notes, and snippets.

@duemunk
Last active January 19, 2016 11:25
Show Gist options
  • Save duemunk/34babc7ca8150ff81844 to your computer and use it in GitHub Desktop.
Save duemunk/34babc7ca8150ff81844 to your computer and use it in GitHub Desktop.
let mainQueueA = dispatch_get_global_queue(qos_class_main(), 0)
let mainQueueB = dispatch_get_main_queue()
// This works fine
dispatch_apply(3, mainQueueA) { i in
println("A: \(i)")
}
println("Yep")
// This never calls the block and hangs the main thread
dispatch_apply(3, mainQueueB) { i in
println("B: \(i)")
}
println("Never called")
// The printout is of running this code on OS X 10.10 or iOS 8.0 is (something like):
// AAA::: 201
//
//
// Yep
// ... and then nothing :/
// 1. Zero CPU usage
// 2. Pausing the debugger show that the main thread hangs in semaphore_wait_trap ()
// 3. It turns out dispatch_get_global_queue(Int(qos_class_main().value), 0) does NOT(!) return the main queue,
// but the concurrent user-nteractive queue.
// Lesson to be learned: If you want the main queue, use dispatch_get_main_queue()
// and NOT(!) dispatch_get_global_queue(Int(qos_class_main().value), 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment