4 ms·
You can compile on x86 for atomic increments? (Go seems to support it https://golang.org/pkg/sync/atomic/ https://golang.org/pkg/sync/atomic/)
by hurin 11y ago
You can compile on x86 for atomic increments? (Go seems to support it https://golang.org/pkg/sync/atomic/ https://golang.org/pkg/sync/atomic/)
- Matt3o12_ 11y agoI don't know but I think so. I just wanted to give him an oversimplified example (you could also use any complicated computation). I'm not sure, though, if every compiler/interpreter makes use of them (what about VMs)?
- jzelinskie 11y agoThis is available only under certain architectures (x86 is one of them as you've noted), but I've also seen scenarios where the atomic increment instruction is actually slower than using a mutex. Don't consider this feature to be a magic bullet and always test your use cases! As for the parent discussion, usually a mutex is talking about the threading construct while a "lock service" is how you'd refer to something like etcd or zookeeper.
- hurin 11y agoHow could it be slower than a mutex? Is it from compiling all your increments to use LOCK? What exactly were you timing? That sounds really strange..
- YZF 11y agoMutexes are typically implemented over atomic instructions. So you'd do something like atomic compare/exchange to acquire the mutex and if there's no contention you got it. If there is contention you go to the OSes synchronization constructs which are typically much slower... An atomic increment should always be faster than acquiring a mutex and incrementing...