2 ms·
eh, not so accurate. it's true that you can't have int i; and write i++. but neither do you need a mutex. for instance, you may just need std::atomic<int>, w
by jepler 10y ago
eh, not so accurate.
it's true that you can't have int i; and write i++.
but neither do you need a mutex. for instance, you may just need std::atomic<int>, which (except on a very unusual system) is not going to be implemented with a mutex. On x86 linux, it's the "lock incl" instruction (vs an "incl" instruction which has the problems the author outlines)
- madmax96 10y agoThis. Plus, using a mutex requires that you obtain all your locks in a consistent order, etc. which opens up a whole can of concurrency worms. All you need is some intern who didn't properly read the documentation writing code that could deadlock. Atomic access is usually what you want.