Every Golang Dev Should Know This: Atomic Values #shorts

preview_player
Показать описание
One of the best features of Golang is its concurrency. But most people are using go concurrency wrong. Atomic values are a very important tool to avoid race conditions. In this short golang tutorial I will show you a nice way to use atomic values to protect your data against race conditions.

📢 I am also building a Discord community! Feel free to join if you are willing to learn about blockchain, web3, Defi, and quantitative trading. Or just hang out and chat.

► Support me on PATREON and get access to exclusive lessons, tutorials, and LIVE streams

► Join my Discord community for free education

► Follow me on GitHub

► Follow me on Twitter

#golang #programming
Рекомендации по теме
Комментарии
Автор

An alternative way of handling this is to simply declare the count with type atomic.Int32 and use the add and load methods. Not saying it's better but helpful to know you have that option as well.

sczoot
Автор

You say they are doing it wrong, but I don't see too many goroutines setup like this. If you're running a goroutine on a numeric value then atomic is the correct solution, but if you're using any other data type (usually a struct) then you would just use mutexes.

YouReyKarr
Автор

How is atomicity implemented here? Does it use mutexes under the hood or is there some built-in atomic add in the CPU or OS?

nesssel
Автор

what's the theme you're using?

mahatmawisesa
Автор

why does it became 20x slower than it was?

shgpavel
Автор

So this is essentially the Go way of using the "volatile" keyword in C?

ForeverZer
Автор

Welp, Rust's compile time safety is gone, now I have to actually thing... UGH.

max_ishere
Автор

How do you even know when to use a Mutex or an Atomic??

jerrythegat