► Join my Discord community for free education 👉 discord.com/invite/bDy8t4b3Rz ► Become a Patreon for exclusive tutorials👉 www.patreon.com/anthonygg_ ► Buy me a coffee 👉 donate.stripe.com/aEU2a6ayH2uCa3u4gg Thanks for watching
Hands down. This is one of the most informative golang videos i have come across in the last 5-6 years. Thanks sir. your style of explaining by writing code on fly is tough to do which shows your command in the language but very informative for us. Pls keep up your great work and share your great knowledge on other languages like c++ and Rust too.
I'm a little unclear on how the atomicity is maintained when you have one atomic load to fetch the health, then an atomic store to set the new health. What would happen if two goroutines tried to update the health at the same time? A: atomic read health (e.g. 10) B: atomic read health (e.g. 10) A: atomic write health = 10 - 1 -> 9 B: atomic write health = 10 - 2 -> 8 Final result should be 7, but it's 8. Is this not how it works? Or is the atomicity somehow maintained between calls? Unless there's an atomic increment/decrement operation, it seems like the better choice for this situation would be mutex even if it's slower
Great explanation, thanks. One more question, can you mix mutex and atomic? Will they respect each other? For example in one goroutine use mutex to modify whole struct and in another goroutine modify only one member of that struct with help of atomic?
► Join my Discord community for free education 👉 discord.com/invite/bDy8t4b3Rz
► Become a Patreon for exclusive tutorials👉 www.patreon.com/anthonygg_
► Buy me a coffee 👉 donate.stripe.com/aEU2a6ayH2uCa3u4gg
Thanks for watching
Hands down. This is one of the most informative golang videos i have come across in the last 5-6 years. Thanks sir. your style of explaining by writing code on fly is tough to do which shows your command in the language but very informative for us. Pls keep up your great work and share your great knowledge on other languages like c++ and Rust too.
Thanks man!
This is the best mutex explanation ive seem. Makes perfect sense now thanks man
Nice explanation mate! And an flowly understandable example ❤
Very nice and informative video. I never knew what Mutex is and what Atomic is but now I get to understand it and when and why use each. Tnx!
Thanks for the video, new to Golang and was waiting for you to make video on Mutexs :P
Great example, thanks Anthony 👍
Nice tutorial everything explained clean!
Haven't covered this subject, greate one!
Thanks for the video!
Mutex is slower than Atomic, b/c it blocks other gorountines. Just go with Atomic
I'm a little unclear on how the atomicity is maintained when you have one atomic load to fetch the health, then an atomic store to set the new health. What would happen if two goroutines tried to update the health at the same time?
A: atomic read health (e.g. 10)
B: atomic read health (e.g. 10)
A: atomic write health = 10 - 1 -> 9
B: atomic write health = 10 - 2 -> 8
Final result should be 7, but it's 8. Is this not how it works? Or is the atomicity somehow maintained between calls? Unless there's an atomic increment/decrement operation, it seems like the better choice for this situation would be mutex even if it's slower
you are right, he should have used atomic.AddInt32
Great explanation, thanks. One more question, can you mix mutex and atomic? Will they respect each other? For example in one goroutine use mutex to modify whole struct and in another goroutine modify only one member of that struct with help of atomic?
8:30 - Isn’t this wrong because the loop will break before unlocking the mutex? You’d want to add another Unlock() call right before the break right?
I thought the same, not sure though.
💥💥💥
just use message passing so we can maintain your code. don't use synchronization primitives.