► 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
@nsgirish Жыл бұрын
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.
@anthonygg_ Жыл бұрын
Thanks man!
@joeyhills2126 ай бұрын
This is the best mutex explanation ive seem. Makes perfect sense now thanks man
@LNMLucasMasiero17 күн бұрын
Nice explanation mate! And an flowly understandable example ❤
@RootsterAnon Жыл бұрын
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!
@ericrichard4482 Жыл бұрын
Thanks for the video, new to Golang and was waiting for you to make video on Mutexs :P
@DeepakKumar-ze8iiАй бұрын
Great example, thanks Anthony 👍
@oneke4498 Жыл бұрын
Nice tutorial everything explained clean!
@thanhvo8798 Жыл бұрын
Mutex is slower than Atomic, b/c it blocks other gorountines. Just go with Atomic
@tpotjj2979 Жыл бұрын
Haven't covered this subject, greate one!
@JarodLatta-b6s Жыл бұрын
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
@DavidFregoli Жыл бұрын
you are right, he should have used atomic.AddInt32
@sovrinfo Жыл бұрын
Thanks for the video!
@oleksiistri84295 ай бұрын
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?
@hocky-ham324-zg8zc Жыл бұрын
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?
@anuragbisht1200 Жыл бұрын
I thought the same, not sure though.
@alexmeh19199 ай бұрын
💥💥💥
@Amine-gz7gq7 ай бұрын
just use message passing so we can maintain your code. don't use synchronization primitives.