I am ios development Beginner Studying mutlithreading. Let me Know If I am wrong
I studied that
Serial Queue : 1 thread.
Concurrent Que : multiple thread for each task.
Sync Task : blocks other task till its completion
Async Task : tasks can run parallely..
I write a code for Concurrent Queue sync Tasks VS Serial Queue Async Task as follows :
print("Concurrent Que Sync task ")
let que1 = DispatchQueue(label: "AAA", attributes: .concurrent)
que1.sync{
print("Que1 Started")
for index in 1...3{
print("1.\(index)")
}
print("Que1 Ended")
}
let que2 = DispatchQueue(label: "BBB", attributes: .concurrent)
que2.sync{
print("Que2 Started")
for index in 1...2{
print("2.\(index)")
}
print("Que2 Ended")
}
print("Serial Que Async task")
let que1 = DispatchQueue(label: "AAA")
que1.async{
print("Que1 Started")
for index in 1...3{
print("1.\(index)")
}
print("Que1 Ended")
}
let que2 = DispatchQueue(label: "BBB")
que2.async{
print("Que2 Started")
for index in 1...2{
print("2.\(index)")
}
print("Que2 Ended")
}
I got output as :
Concurrent Que Sync task
Que1 Started
1.1
1.2
1.3
Que1 Ended
Que2 Started
2.1
2.2
Que2 Ended
Serial Que Async task
Que1 Started
Que2 Started
2.1
2.2
Que2 Ended
1.1
1.2
1.3
Que1 Ended
I just have Question in case of Concurrent Que sync task : as we have conc queue then we will have 2 threads & we can run only 1 task at a time on both que as it is sync thennnnn why it starting task2 after completion of task1 insteading of running on two seprate therad parallely.
As well as
in case of Serial Que Async task : as we have Serial queue then we will have only 1 threads & we can run multiple task but due to only 1 thread we have to run task2 after task1. Then how it is running 2 task parallely..
PS: Correct me if I missunderstood