dispatch_async(dispatch_get_main_queue(), { () -> Void in
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
for j in 0...10 {
print("alpha \(j)")
}
})
for i in 0...10 {
print("beta \(i)")
if i == 4 {
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
for j in 0...10 {
print("gamma \(j)")
}
})
}
}
})
Do not call the dispatch_sync function from a task that is executing on the same queue that you pass to your function call. Doing so will deadlock the queue. If you need to dispatch to the current queue, do so asynchronously using the dispatch_async function.