
Why you need a mutex to protect an int - asandler
http://www.alexonlinux.com/why-you-need-a-mutex-to-protect-an-int
======
jepler
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
This.

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.

