Answer the question
In order to leave comments, you need to log in
How will blocks behave with such a sequence?
How will blocks behave with such a sequence, what will be the result?
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)")
}
})
}
}
})
Answer the question
In order to leave comments, you need to log in
There will be a lock , since you are trying to add a synchronous task to the queue, already "being in the queue"
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question