iOS Dev 17: Semaphore vs DispatchGroup | Swift 5, XCode 11

  Рет қаралды 3,243

Emmanuel Okwara

Emmanuel Okwara

3 жыл бұрын

Today we learn about the differences between the DispatchGroup and DispatchSemaphor.
We highlight the dangers of using a DispatchGroup with shared resources and see how Semaphores are able to handle it.
Additional Resources:
Link to project: github.com/EMacco/ios-tutoria...
Say Hi on Social Media:
LinkedIn: / emacco
Twitter: / its_macco

Пікірлер: 35
@ElitePanCake645
@ElitePanCake645 2 жыл бұрын
Clear and concise explanation. Good job.
@jackshephard7920
@jackshephard7920 3 жыл бұрын
Everything is so clear, thanks!
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
I'm glad you liked it
@shabibhossain
@shabibhossain 3 жыл бұрын
Great explanation, keep up the amazing work! 👍
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
Thanks Ahmad 😊
@akshaykumar-qj2kx
@akshaykumar-qj2kx 3 жыл бұрын
explanation is easy to understand.. Good work
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
Thanks, Akshay 😊
@ranganathchenna4559
@ranganathchenna4559 Жыл бұрын
Nice explanation 👏🏼
@magedmohmed4403
@magedmohmed4403 2 жыл бұрын
Great Work . Thank You for this explanation
@Swcake1
@Swcake1 2 жыл бұрын
Watching this video made me a little bit clever. Thank you!
@EmmanuelOkwara
@EmmanuelOkwara 2 жыл бұрын
That’s awesome! 😊
@KaizenM1989
@KaizenM1989 3 жыл бұрын
That was explained very well. Thank you!
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
It’s my pleasure 😊
@libvlog2264
@libvlog2264 Жыл бұрын
GCD is a very cool api. You really do great with these videos.
@EmmanuelOkwara
@EmmanuelOkwara Жыл бұрын
Thank you 😊
@SahharYoucef
@SahharYoucef 3 жыл бұрын
Great content, i really like your way of explanation
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
Thanks, Sahhar 😊
@1youbest
@1youbest 3 жыл бұрын
Great Explaination
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
Thanks, Waqas 😊
@emmygozi9295
@emmygozi9295 3 жыл бұрын
Great content as always..
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
Thanks bro
@daniisemenov
@daniisemenov 3 жыл бұрын
Thanks it's so useful!
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
I'm glad you liked it 😊
@mittalbhandari6627
@mittalbhandari6627 11 ай бұрын
Well Explained :-)
@vamseeg1097
@vamseeg1097 3 жыл бұрын
Nice explanation :)
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
Thanks 😊
@rebellious_703
@rebellious_703 2 жыл бұрын
in semaphore section, what is second block executive ls first ? line 31 to 36
@raychen4458
@raychen4458 2 жыл бұрын
Emmanuel, thank you for the great explanation !. I still have a bit confusion as how system knows when it should execute download or save first. Then the other one will wait. Since both download and save tasks share the same queue and are executed concurrently. if saving task runs first and downloading task waits, Xcode still crashes right ? Will the system still executes the async task based on the order of those tasks?
@EmmanuelOkwara
@EmmanuelOkwara 2 жыл бұрын
Great question, Ray. First, code is executed line by line. If a line takes more time to execute, it delays the execution of the rest. Second, “save” will crash if it runs first because our save method uses a resource that’s not yet available. Finally, it’s also important to note that tasks within a sync/async block are executed synchronously by default unless you specify it as an async.
@user-mx6hg8vx5o
@user-mx6hg8vx5o 3 жыл бұрын
Why don't you write "semaphore.wait" before queue.async?Can u tell what is the difference in writing like I said and you showed in video?Thanks for answer in advance)
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
Good question Анна, Remember that the semaphore.wait() blocks the thread from executing until the resource is available. If we were to add this line of code to the main thread (outside the queue.async), it'll check if the resource is available. If it is, it will execute normally, otherwise, it'll cause the app to freeze until the resource is available. You can easily simulate this by following these steps: 1. Comment out the semaphore.signal() in the first queue.async block (to make sure the resource is not made available) 2. Move both instances of semaphore.wait() outside their respective queue.async blocks (as mentioned in your question) 3. Change the background color of the view after the second queue.async block (for a visual test) 4. Run the app Notice that the background color was never changed.
@user-mx6hg8vx5o
@user-mx6hg8vx5o 3 жыл бұрын
@@EmmanuelOkwara Oh, thank you.But I have one more question, if we use enter() on the main thread for dispatch group is it ok?
@EmmanuelOkwara
@EmmanuelOkwara 3 жыл бұрын
@@user-mx6hg8vx5o The essence of the enter() is to "indicate" that a block of code has entered into the group, it is safe to put that on the main thread. wait() on the other hand blocks the caller thread so it is usually better to avoid it and maybe go for the notify() instead
@dannybones9484
@dannybones9484 2 жыл бұрын
enter/leave for group work similar tho
@EmmanuelOkwara
@EmmanuelOkwara 2 жыл бұрын
Yeah. It’s quite similar.
iOS Dev 18: Error Handling (Try|Do|Catch) | Swift 5, XCode 11
16:06
Emmanuel Okwara
Рет қаралды 1,2 М.
Luck Decides My Future Again 🍀🍀🍀 #katebrush #shorts
00:19
Kate Brush
Рет қаралды 8 МЛН
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 10 МЛН
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,5 МЛН
Я нашел кто меня пранкует!
00:51
Аришнев
Рет қаралды 2,5 МЛН
When to Semaphore vs Dispatch Group! Careful Multithreaded Shared Resource
11:11
iOS Dev 44: Connecting XCode 13 to GitHub | Git Workflow
17:00
Emmanuel Okwara
Рет қаралды 3,8 М.
A Day in the Life of a Software Engineer in Berlin, Germany
7:23
Emmanuel Okwara
Рет қаралды 21 М.
iOS Dev 43: Collaboration with Git & Xcode 13 Explained with illustration
29:07
tRPC, gRPC, GraphQL or REST: when to use what?
10:46
Software Developer Diaries
Рет қаралды 71 М.
How to use MVVM with Async Await | Swift Concurrency #14
11:42
Swiftful Thinking
Рет қаралды 8 М.
После ввода кода - протирайте панель
0:18
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 1,9 МЛН
cute mini iphone
0:34
승비니 Seungbini
Рет қаралды 6 МЛН