DispatchQueues: Serial, Concurrent, Async, & Sync - Overview

  Рет қаралды 24,525

iOS Academy

iOS Academy

2 жыл бұрын

In this video we will dive into the differences of serial and concurrent dispatch queues. A pillar of iOS Development to schedule work, we'll also talk through sync and async work being executed with examples.
💻 Source Code: / iosacademy
🎥 Subscribe for more: kzfaq.info?su...
😎 Like my teaching style? Check out some of my most popular courses! courses.iosacademy.io
** Popular Series
Building Instagram: courses.iosacademy.io/p/build...
Building TikTok: / @iosacademy
SwiftUI for Beginners: ios-academy.teachable.com/p/s...
** Get Skillshare free for 2 Months and learn iOS
www.skillshare.com/r/user/afraz
** Manage all your investments from app earnings on Betterment!
bit.ly/3eBwlI9
** Grow your own KZfaq tech channel with TubeBuddy:
www.tubebuddy.com/iosacademy
#swift #concurrency #iOSDeveloper

Пікірлер: 53
@hibviow
@hibviow 2 жыл бұрын
You did not explain sync vs async really well. The main difference between those is: Sync: Blocks the caller queue until the task is done (serial or concurrent. Async: Does not block the caller queue. Serial queue: Executes tasks one after the other in just one thread Concurrent queue: Executes tasks in parallel in a different queue's thread On your first example, the main reason why it printed "1" it's because you can never call sync{} from the same queue AND to the same queue (serial or concurrent). You'll end up with a deadlock and a crash most of the time.
@tonysiu8562
@tonysiu8562 2 жыл бұрын
wow this comment should be placed on top
@laurapotter6321
@laurapotter6321 2 жыл бұрын
could you explain a bit more on the 1st example please? What do you mean "you can never call sync{} from the same queue AND to the same queue (serial or concurrent)"?
@tonysiu8562
@tonysiu8562 2 жыл бұрын
@@laurapotter6321 if u call sync from the same queue and to the same queue. The sync routine will need to start after retuning from the sync routine. And the sync function call cannot return until the sync routine finished. So it becomes a dead lock
@laurapotter6321
@laurapotter6321 2 жыл бұрын
@@tonysiu8562 but in his 1st example, there is only one sync called on the queue right? Where is “from and to the same queue ” coming from?
@tonysiu8562
@tonysiu8562 2 жыл бұрын
@@laurapotter6321 In the example at the very beginning of this video, it is serial queue. Serial means, one task has to be completed before the next task can start. .async{} is retuning even the task isnt started. since the sync{print "2"} is inside async{ print"1" ... } the task in the print"2" routine cannot start before the everything in print"1" routine can finish runnin.
@Karan-jr9eo
@Karan-jr9eo 2 жыл бұрын
This channel is a gold mine for those who want to develop and sharpen their iOS development skills! Thanks man!
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Thanks!
@everyontech2716
@everyontech2716 2 жыл бұрын
Great content man
@muro12345muro
@muro12345muro 2 жыл бұрын
Great content man, keep up the good work & ty for your effort
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Thanks
@duongthang5132
@duongthang5132 2 жыл бұрын
Awesome, I have been waiting for this
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Thanks
@makwanbarzan7085
@makwanbarzan7085 2 жыл бұрын
Well explained. Thanks!!
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Youre welcome
@jayaseelankumarasamy7093
@jayaseelankumarasamy7093 2 жыл бұрын
Great one, do more videos related to concurrent and thread concepts
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Thanks!
@abdulrahim46
@abdulrahim46 2 жыл бұрын
@@iOSAcademy Yes, Please do more of these! Thank you.
@baskaran180
@baskaran180 2 жыл бұрын
Thanks for posting man!
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Youre welcome
@pedroalonsoms
@pedroalonsoms 2 жыл бұрын
you are the best teacher thanks
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Thanks
@ashokkumar-nq1ic
@ashokkumar-nq1ic 2 жыл бұрын
Great video sir....
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Thanks
@laurapotter6321
@laurapotter6321 2 жыл бұрын
thank you! could you make a video to explain the iOS app lifecycle?!! Thank you again! love this channel so much!
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Coming soon
@martinq872
@martinq872 2 жыл бұрын
Oh, my god... I always hard to understand this. thx so much 😭 actually many answer replied on your community and I am one of them LOL
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Haha nice
@dasturchi3684
@dasturchi3684 2 жыл бұрын
Hi Afraz, please put all 2021 swift tutorials in one playlist
@paulancajima
@paulancajima 2 жыл бұрын
thank you
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Youre welcome
@proxa2087
@proxa2087 2 жыл бұрын
I still don’t understand why only “1” printed at the beginning…
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Bc it locks the serial queue
@sharungarg
@sharungarg 2 жыл бұрын
So to understand it, when we are calling sync, we are telling the queue to make itself available, free from any ongoing tasks (sync or async) or just complete the current task and make itself available. But as the sync block was called inside the async block, although the queue can put the async operation on hold and take other tasks, but cannot make itself completely available for the sync block to run. The sync block is demanding the full availability of the queue, but the ongoing async block cannot complete unless that sync block completes. Can someone please confirm it?
@user-jt6uu1ru7s
@user-jt6uu1ru7s 2 жыл бұрын
I tried before with a certain api to make a request serially by write a code as you did but it did not work. Does "task.resume()" or "session" have an effect on that?
@rev_kous9275
@rev_kous9275 2 жыл бұрын
More content with Reactive Programming with RxSwift and also about Clean Architecture.
@ho6y
@ho6y 2 жыл бұрын
queue.sync refers to that particular queue doesn't it? instead if you specifically point to queue.main.sync would be the same than not using the queue itself since you're poining right to the main thread am i right?
@jameelshehadeh9011
@jameelshehadeh9011 2 жыл бұрын
i get it why 1 is printed in the first block of code i.e queue.async { print("1") queue.sync { print("2") queue.sync{ print("3") } } } but why the last two async blocks containing "4" and "5" are not executed despite them being called out of the first scope ? i tried to think about it and thought because the queue will be busy performing print("1") but it supposed to be serial so once its finished the first block it will move to execute the next two blocks i believe there is something i am misunderstanding here its confusing little bit, would appreciate some help
@osmansuliman5226
@osmansuliman5226 Жыл бұрын
Since the first closure submitted to the serial queue contains a sync call, it blocks the serial queue until the closure has finished executing. This means that the async calls for "4" and "5" are not executed until the first closure has finished executing.
@protodimbo
@protodimbo 2 жыл бұрын
Hey 👋 You forgot to talk about concurrency problems such as race conditions, deadlock etc
@protodimbo
@protodimbo 2 жыл бұрын
You actually can make whole playlist about concurrency. There is threads, gcd, operations, qos
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Follow up video
@sumeetbhujang2756
@sumeetbhujang2756 2 жыл бұрын
But still it's not clear to me why it printed "1" and not 1,4,5
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Bc it locks the serial queue
@stotchmania
@stotchmania 2 жыл бұрын
@@iOSAcademy Hi. But why does it lock the queue? Thanks!
@csmac3144a
@csmac3144a 2 жыл бұрын
Sorry but you didn't explain many things. Why did the 1 print? The difference between sync and async is not clear from your explanation or example.
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Deadlock
@oleksandrbalan5931
@oleksandrbalan5931 2 жыл бұрын
I respect your intention to try to explain things, but your explanation of sync/async is just bad and might only confuse fresh iOS devs
@iOSAcademy
@iOSAcademy 2 жыл бұрын
Thanks for the feedback
@TheScrinn
@TheScrinn 8 сағат бұрын
queue.sync - impossible to call, code crashes. Did tried to copy code from screen as is and that crashes in runtime. don't spend time on video, marked with dislike
Strong vs. Weak Swift 5: What is Weak Self (Xcode 11, 2020)
16:41
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 38 МЛН
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН
Async Sequence in Swift (2022)
11:11
iOS Academy
Рет қаралды 9 М.
Threads and Grand Central Dispatch in Swift
22:14
Stewart Lynch
Рет қаралды 21 М.
iOS System Design Interviews: Introduction & Resources
16:09
iOS Academy
Рет қаралды 28 М.
Main Thread, Sync vs Async and Deadlocks in Swift
9:49
iCode
Рет қаралды 13 М.
002. Дмитрий Галимзянов «GCD»
11:42
Yandex for Developers
Рет қаралды 8 М.
DispatchQueue Interview Question | Swift Coding Problem | Most Confusing Problem
5:10
iOS Interview Preparation
Рет қаралды 4,2 М.