Mastering Concurrency in iOS - Part 2 (Dispatch Queues, Quality of Service, Attributes)
HTML-код
- Опубликовано: 1 авг 2024
- In this video, I have discussed Dispatch Queues in detail. System provided queues, custom queues, main queue, Quality of Service, why QoS was introduced, attributes like concurrent, initiallyInactive.
Apart from these, a little advanced concepts like target queue, and auto release frequency have also been discussed.
00:00 Start
1:50 Main Queue
3:32 Global Concurrent Queues
7:47 Quality of Service
17:57 QoS in Action (code)
23:04 Attributes
24:03 Target Queue
28:28 Target Queue in Action (code)
33:36 Auto Release Frequency
39:44 Custom Queue using Main Thread
Explained very well. Thanks a lot!
Excellent work done...congratzzzzzzz
I listen only audio without video, still able to grasp many of the concepts.... Clear explanation throughout.
I did watch the video again for the code examples though.....its my habit to listen podcasts while driving. 😊
Love your videos, so helpful!
I feel so lucky to have looked for this topic and found this video, especially just less than a week after it was uploaded! very informative and helpful! Can't wait for the interview questions video as I got my interview in about a week! Pressure is on! Thanks so much again! :)
One of the best explanations of Concurrency I have come across. Really a great one. Even someone who has no idea about concurrency can understand the topics. Well done.
Good explanation as always. heavily depending on your explanations. thanks mate. Cheers!!!
This man is just awesome with great content and thoughts on every topic he covered in his videos collection. 🤞
This was so well planned and so well explained ☺.
Im not joking
The way he explain concept, deep dive in the problem and provide improvement are really interview style. I passed my interview with help of this video. Thank you, keep doing this video !!!
You've given your best explaining these concepts Pallav.
These things can be very confusing, I've been there.
This is, by far, one of the best series on any swift topics.
I can imagine how much hard work has gone into grasping all this and making the series comprehensive enough for all out there.
Thanks for sharing your years of hard work and knowledge with us and enlighten us.
Really appreciate.
I'm an android dev trying to understand iOS concepts so that I can write kmm libraries. This is the clearest explanation of gcd. Thank you
Sorry to comment again… this video series is absolutely blowing my mind. Such interesting content. The fact that the system decides to delegate tasks on the main thread in order not to freeze the rest of tasks when running synchronously is another example of how meticulous and detailed Apple designs it’s system. Unexpected outcome, but it makes sense and I love it! Congrats and thanks for these very well explained concepts!
interesting thing is he is taking extra effort and creating editing video at 1:00 AM to 2:00AM
Crystal clear explanation!!! Kudos for the effort you are putting to explain each and every concept from basics to advanced!
The examples you have in these videos are extremely helpful. I really appreciate how you give an example and then give time to pause to think through the order of task completion is wonderful and helps me so much to understand the concepts. I said it on the last video and will say it again, this is the best video I've seen to help understand these tough concepts. You are doing a great job, thank you very much.
Explained very well. Thanks Pallav
Great Effort. Keep posting
Hey Pallav, really admire your work, I have 11 years of iOS developer experience but the way you explained really eye opener for me. I am using custom queues from long time but my thinking was little bit wrong. You cleared the concept, eagerly waiting for next videos.
Great work. Thanks 😊
Hi Pallav, this content, is next level keep making more & more
Keep sharing, Thanks Pallav
Thank you sir, It is very helpfull, Amazing skills you have to teach other such heavy topics in a very easy way.
Super hero, Very well explained.Thanks
27:50 great learning. Thanks a lot!
Great work
Hi Pallav, Hope you are doing great. Outstanding explanation on Multithreading. Please keep posting more videos related it iOS. Please share your code snippets which you are using in real time projects which might help us to reduce development time.
Nice one!
Hey pallav your videos on iOS app development are very good and understandable. please upload maximum videos in one month
Good serious
Thanks for the awesome video! I have a question about the target queue. I see the video mentioned if we don't specify a target queue, it's 'default priority global queue' by default. Does it mean by default the target queue is a concurrent queue even if the DispatchQueue is a serial queue? Thanks
Great work Pallav. I am also an ios dev working in Byju's hope oneday we will meet for a great discussion 😊.
Sure Ashutos, looking forward to it.
Thanks for the awesome videos! i am watching this playlist second time so will post some of my doubts in all videos hope u will answer.
I have a question about the target queue. I see in the video mentioned at 30.50 if we don't specify a target queue, it's 'default priority global concurrent queue' by default. Does it mean by default the target queue is a concurrent queue even if the DispatchQueue is a serial queue? in that case queue name "A" should behave as concurrent queue not serial queue. pls confirm ?
To understand how target queues consolidate threads, this is a better example. If you use the example given where there are only two queues a and b, and a targets b, you will still have separate threads.
let t = DispatchQueue(label: "T")
// try removing the target parameter to see the difference in thread
let a = DispatchQueue(label: "A", attributes: .concurrent, target: t)
let b = DispatchQueue(label: "B", target: t)
a.async {
for num in 1...5 {
print("\(num) \(Thread.current)")
}
}
a.async {
for num in 6...10 {
print("\(num) \(Thread.current)")
}
}
b.async {
for num in 20...24 {
print("\(num) \(Thread.current)")
}
}
Difference between qos userinteractive & main thread and an example where we must use userInteractive & cant use main thread?
How many global concurrent queues we have? Do we have separate queues for handling each QoS?
Hey, Need Link for article link from Aina Jain with Code snippet please.Thank you for great video, got to know new concepts like auto release pool, Target queue now.
Question: if a custom queue inherits behaviour from the target queue and then if you don't explicitly specify a target then as you mentioned it will use the default global queue as it's target (qos: default) then: at this point custom queue is by default concurrent queue no matter what attribute you specify because in last video you mentioned all global queues are concurrent in nature?
That means in 31:18, queue A should actually be concurrent queue no?
Is this some missing explanation to this?
More specifically "If custom queues always inherit target queues then in case of serial custom queues what queue will be the default target queue? "
same question i m also having if u get answer pls let me know as well
Where is document link which you mention in video ?
Kindly share aina jane articles url
what is the important of the label ??
Link to the articles ?
0 should always come before 11 since user initiated would be start before background.
Can you link the articles you mentioned during auto release frequency example?
yes, Pallav please do that
39:06 - why is "task running in other thread" printed before "Last line in playground"?
same question, please explain
Because by the time control reached at the "Last line in playground", the async block submitted to the serialQueue (didn't matter if it was a concurrent queue) started being executed. Remember - all queues are concurrent relative to each other.
At 6:15 why was second statement executed first rather than the first statement, as both are assigned asynchronousily?
Both are assigned async. but the Queues are different and Threads are different.
same question i m also having if u get answer pls let me know as well
Because main thread is busy by default trying to do UI things. If you print a lot of numbers (say 10000) in a loop in both queues, you will see that main and background queue are intermingling - but background queue will print lot of things first. That is because by default background queue does not have much to do, so it finishes the tasks faster. (This would change if your background queues were doing heavy operations).
@@theakshatpatel I tried the printing of both, they don't intermingle. That being said, the main thread being busy is correct. If you replace the main queue with a created serial queue, the serial queue will run first.
Where is a code running when it's not inside main/global or custom queue?
In Background Queue.
By default it is main queue.
👌
DispatchQueue.main.async {
if(Thread.isMainThread)
{
print("main thread")
}
for i in 0...5
{
print("user main \(i)")
}
}
DispatchQueue.global(qos: .background).async
{
if(Thread.isMainThread)
{
print("user background main thread")
}
else
{
print("user background not a main thread")
}
for i in 0...5
{
print("user background \(i)")
}
}
output:
user background not a main thread
user background 0
user background 1
user background 2
user background 3
user background 4
user background 5
main thread
user main 0
user main 1
user main 2
user main 3
user main 4
user main 5
why main thread task is executed at the end?
Because main thread is busy by default trying to do UI things. If you print a lot of numbers (say 10000) in your background queue, then you will see that main queue is not always printing after the background queue. Since the background concurrent queue generally does not have anything to do, it will finish printing first - but not always. You can test this by printing large number of values not just 5 in your loop.