WaitGroups - Part 1 (Concurrency in Go #2)

  Рет қаралды 11,260

Steve Hook

Steve Hook

Күн бұрын

In this video you'll learn what is a WaitGroup, how to use WaitGroups and a bunch of WaitGroup issues and ways to mitigate them. By the end of this video you'll have a solid idea on WaitGroup Basics in Go
#golang #steevehook #concurrency #waitgroups
00:00 - Intro
01:19 - Concurrency Primitives Intro
02:10 - Wait on Condition
02:49 - Without WaitGroup Example
04:43 - Basic WaitGroup Example
06:50 - With WaitGroup Example (Fix)
08:26 - WaitGroup Issues Intro
08:41 - No Add Example
09:58 - WaitGroup Deadlock Example
11:02 - WaitGroup Negative Counter panic Example
12:01 - WaitGroup passed by Value panic Example
13:49 - WaitGroup Reuse panic - Simple Example
15:28 - WaitGroup Reuse panic - Loop Example
17:41 - Outro
Enjoy 🚀💻🚀
✍ RESOURCES:
► github.com/golang-basics/conc...
💰 Support me on Patreon:
► / steevehook
💰 Paypal Donation:
► paypal.me/steevehook
💰 Buy me a Coffee:
►www.buymeacoffee.com/steevehook
🐧 FEEDBACK:
► gophertuts.typeform.com/to/j2...
💬 COMMUNITY:
► / discord
💻 GITHUB:
► github.com/gophertuts
► github.com/steevehook
💻 Repl.it:
► repl.it/@steevehook
💻 Exercism:
► exercism.io/profiles/steevehook
📖 Medium:
► / steevehook
💬 TWITTER:
► / @steevehook
💬 FACEBOOK:
► / steevehookmd
💬 REDIT:
► / steevehook
💬 INSTAGRAM:
► / steevehook
✉️ EMAIL
► steevehook@gmail.com
⚡ WEBSITE:
► www.steevehook.com
🎧 Music:
► www.epidemicsound.com/referra...
► artlist.io/Steve-411836
🎥 Gear used:
► Sony 𝛼7III
► Rode NTG-3
► Golden Age Project Pre73-JR preamp
______________________________________________________________________________
Software engineering is one of the most accessible fields nowadays, but it's easy to get lost in the huge amount of technologies and ways to approach engineering problems. Lots of languages, frameworks, solutions and ways to be a productive engineer.
I share my own experience on what is like to be a software engineer and the skills required to be a productive one. On this channel I share my thoughts, opinions and video tutorials about topics related to a certain technology, to make it easier for you to ultimately make a choice or just get better at software engineering by learning from my mistakes/experience.
Make sure to also check out 5m Friday every Friday, where I share my thoughts and opinions about different engineering topics. I'll c you around 😎
Stay tuned!
🚀💻🚀

Пікірлер: 63
@HarishVangavolu
@HarishVangavolu 3 жыл бұрын
This is the highest production quality I've seen on KZfaq for anything Golang related. Let alone not many content creators and tutorials go this in depth into concurrency. I'm very surprised it doesn't get more views! I rooting for you man! Keep up the good work!
@SteveHook
@SteveHook 3 жыл бұрын
Thank you so much man, really appreciate it ☺️☺️😌
@alonzathompson9033
@alonzathompson9033 Жыл бұрын
The best in-depth video on Go's concurrency model I have seen.
@SteveHook
@SteveHook Жыл бұрын
Thanks a lot Alonza 🥹🥹
@fabio336ful
@fabio336ful 2 ай бұрын
Great concurrency series! The best one. I would like to add something to the "passed-by-value" example: You have to pass a pointer because if not, we are not going to use the same wait group that is outside of the work function (the one with wg.Add(1)), instead a copy will be created inside the function, and this copy doesn't have the added value, this is the reason why you receive a PANIC.
@farouksallam1779
@farouksallam1779 Жыл бұрын
One of the highest quality videos on youtube.
@SteveHook
@SteveHook Жыл бұрын
Honored to read that sir 🥹🥹
@dreb.7760
@dreb.7760 Жыл бұрын
Amazing work, thank you
@krkartick
@krkartick 10 ай бұрын
Awesome video that explained the concurrency very well.. Good Job
@saiaussie
@saiaussie Жыл бұрын
This is great content, no fluff just stuff. Great stuff mate. I'm happy to finally find the go concurrency tutorials what I was looking for a long long time. Thank you Steve!
@SteveHook
@SteveHook Жыл бұрын
You’re welcome buddy, glad u found it useful 💪
@sharanballundagi5592
@sharanballundagi5592 3 ай бұрын
Great content, really in depth. Thanks man for all your effort.
@SteveHook
@SteveHook 3 ай бұрын
You are welcome brother 😢
@cristobaljvp
@cristobaljvp 2 жыл бұрын
High quality videos man, I learned a lot! And I really appreciate you showing common mistakes, cause that's exactly what a begginer will encounter and don't know what to do.
@SteveHook
@SteveHook 2 жыл бұрын
Thanks a ton man, really appreciate it 🖤
@prasanthpn4725
@prasanthpn4725 Жыл бұрын
nice video and easy to understand
@yashwantht3000
@yashwantht3000 2 жыл бұрын
Thank you so much for this amazing content. It's very detailed and of high quality. Keep it going!!
@SteveHook
@SteveHook 2 жыл бұрын
Thank you mate. Definitely will ☺️
@yellowandy
@yellowandy 2 жыл бұрын
very good!
@mikkaruru
@mikkaruru 2 жыл бұрын
the best! ❤
@tusharchaurasia886
@tusharchaurasia886 11 ай бұрын
Wow such great video content. I Read eBook concurrency in go which, i think the content is from there , but reading is so boring. Great work keep it up.
@gronccoravioli
@gronccoravioli 3 жыл бұрын
This is exactly what I needed for my application without even knowing it, thanks!!
@SteveHook
@SteveHook 3 жыл бұрын
No worries, glad you found something interesting ☺️☺️
@diegolopeztorres8841
@diegolopeztorres8841 2 жыл бұрын
As someone who is really thankful for this amazing quality content, I am going to spread out the word about your existence!
@SteveHook
@SteveHook 2 жыл бұрын
Thanks a ton Diego. Really appreciate it ❤️
@sunnyraj84348
@sunnyraj84348 Жыл бұрын
I don't usually comments on videos but your such amazing explanation has made me to do so. Such great content. Thanks buddy, keep it up :)
@SteveHook
@SteveHook Жыл бұрын
Thanks a lot man 🥹🥹
@mrcharm767
@mrcharm767 10 ай бұрын
thanks the world will remember this contribution sunny, I will keep fasting for you such a great person
@user-nz6gy6tg5f
@user-nz6gy6tg5f 2 жыл бұрын
So much work, thank you!
@SteveHook
@SteveHook 2 жыл бұрын
Thanks man 🥺
@punj
@punj Жыл бұрын
I am not sure why your videos have so less views even after a year. Great way to explain concurrency and I am sure other concepts too. Thank you !
@SteveHook
@SteveHook Жыл бұрын
Thanks a lot Puneet ❤️
@learn9475
@learn9475 2 жыл бұрын
the production quality is more than a typical indian action movie , and salute to the work ethics you have thanks for this playlist The best for concurrency in Go
@SteveHook
@SteveHook 2 жыл бұрын
Awww. Thanks a lot LEarn 🤗🤗 Really appreciate it 🥰
@ishankbansal812
@ishankbansal812 2 жыл бұрын
Loved the explanation 😀😀😀
@SteveHook
@SteveHook 2 жыл бұрын
Glad you liked it 😌
@vishnusingh351
@vishnusingh351 2 жыл бұрын
Amazing content with great editing 👌👌👌
@SteveHook
@SteveHook 2 жыл бұрын
Thanks a lot Vishnu
@hectorgool
@hectorgool 2 жыл бұрын
👏👏👏👏👏
@PiyushTyagi-h6z
@PiyushTyagi-h6z 3 күн бұрын
I guess passing wg by value should be deadlock instead of panic as we have two var of wg one in main and one in work func. In main wg counter is not set to 0 (wg.Done() is inside work func hence it will set the counter to 0 for the copied var not for the one in main) hence deadlock.
@3x10.8_ms
@3x10.8_ms 8 ай бұрын
gem
@sanjeevsiva17
@sanjeevsiva17 2 жыл бұрын
We pass waitgroup as a pointer because it's a struct. if we pass as value it will create a copy of waitgroup.
@SteveHook
@SteveHook 2 жыл бұрын
Yes, that’s correct, we need to increment/decrement the same waitgroup’s internal counter, not the copy of the counter inside each process
@cesarcarafuhr
@cesarcarafuhr 3 жыл бұрын
This videos are really good!!!
@SteveHook
@SteveHook 3 жыл бұрын
Thx mate ☺️☺️
@hazemtuber
@hazemtuber 2 жыл бұрын
Thanks for the tutorial, regarding the last example, don't we need a wg.Add(1) for the outer wrapping go routine ?
@hazemtuber
@hazemtuber 2 жыл бұрын
@Steve Hook regarding the last example, don't we need a wg.Add(1) for the outer wrapping go routine ?
@SteveHook
@SteveHook 2 жыл бұрын
A timestamp would be highly appreciated. I have a short memory especially with my lengthy examples 😆
@SteveHook
@SteveHook 2 жыл бұрын
@@hazemtuber If you're referring to WaitGroup reuse panic, yes you're right we normally should have had another wg.Add call on the wrapping go routine, but we would need a new waitgroup instance, we can't use the same waitgroup, otherwise we wouldn't know when the outer go routine is done, because any inner go routine that calls Done will affect the wrapping go routine wait point. This is why for brevity and simplicity I omited it, having a relatively bigger number of inner go routines like 100 in that case, generates the issue I was trying to highlight. Hope this helps
@hazemtuber
@hazemtuber 2 жыл бұрын
@@SteveHook Awesome, I added an outer WG and I'm not getting the error in the wg reuse panic var owg sync.WaitGroup var wg sync.WaitGroup for i := 0; i < 100; i++ { owg.Add(1) go func() { wg.Add(3) go func() { wg.Done() }() go func() { wg.Done() }() go func() { wg.Done() }() wg.Wait() owg.Done() }() owg.Wait() } } Thanks alot for explanation.
@g.sebastiangarces2003
@g.sebastiangarces2003 2 жыл бұрын
Hi Steve, Just a quick question - when I attempted to do the pass-by-value example I instead got a deadlock and not a panic: sync: negative WaitGroup counter. I tripple check with both your video and github repo and I'm now wonder whether I'm making an error somewhere or if the error message has changed? func main() { var wg sync.WaitGroup wg.Add(1) go work(wg) wg.Wait() } func work(wg sync.WaitGroup) { defer wg.Done() fmt.Println("work is done") }
@SteveHook
@SteveHook 2 жыл бұрын
Hey Sebastian, The problem with running my code and yours is definitely in the environment and the number of Go routines running. When I showed the passed by value example I was assuming people would run it on their local machines, which means they are probably running one of the latest Go versions and are not restricted by how many threads are running thus the example should always give back the negative waitgroup counter panic. However, if you're running the example in the Go Playground or set runtime.GOMAXPROCS(1) you may get the deadlock, because there's only one thread of execution which is main and seems to be blocked forever in this case, hence the deadlock. Whereas not setting the number of max procs will result in multiple threads being created and thus only getting back a panic, because the main goroutine can run in separation of the work go routine. Thanks for raising this up. Hope this explains the reason why you get such results
@g.sebastiangarces2003
@g.sebastiangarces2003 2 жыл бұрын
@@SteveHook This is really helpful. Thank you so much. I’m just starting to pick up go and your channel has been by far the best content.
@SteveHook
@SteveHook 2 жыл бұрын
Glad I could help 👊
@nagendraprasad4382
@nagendraprasad4382 3 жыл бұрын
Well explanation steve 😊
@SteveHook
@SteveHook 3 жыл бұрын
Thanks mate ☺️
@regysaputra4409
@regysaputra4409 Жыл бұрын
What text editor are you using?
@SteveHook
@SteveHook Жыл бұрын
Most of the times I use Goland 😎
@georgebenjamin6632
@georgebenjamin6632 Жыл бұрын
Hi Steve, your Patreon link isn't working
@SteveHook
@SteveHook Жыл бұрын
Hmm, just checked, seems to work: www.patreon.com/steevehook
@thachnnguyen
@thachnnguyen 3 ай бұрын
Should already do away with using sleep as an example of sync/wait mechanism. Let's abolish that once and for all. It's just dumb.
@SteveHook
@SteveHook 3 ай бұрын
If it’s dumb just don’t watch sir 😉
@SadSadDeadM
@SadSadDeadM Жыл бұрын
Why wg.Done() may generate a panic? is there any documentation for that topic?
WaitGroups - Part 2 (Concurrency in Go #3)
14:34
Steve Hook
Рет қаралды 7 М.
Introduction to Concurrency (Concurrency in Go #1)
27:54
Steve Hook
Рет қаралды 30 М.
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 28 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 9 МЛН
🤔Какой Орган самый длинный ? #shorts
00:42
WaitGroups - Part 3 (Concurrency in Go #4)
27:40
Steve Hook
Рет қаралды 6 М.
Concurrency in Go
18:40
Jake Wright
Рет қаралды 608 М.
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Anthony GG
Рет қаралды 18 М.
EVERYTHING You SHOULD know about Go Modules (Go Basics #8)
22:08
Master Go Programming With These Concurrency Patterns (in 40 minutes)
46:15
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,6 МЛН
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 6 МЛН
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 868 М.
В России ускорили интернет в 1000 раз
0:18
Короче, новости
Рет қаралды 1,8 МЛН
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 34 МЛН