kaka_ace,
Unfortunately, in case you provided, it is not atomic.
Here's the reason the pre-increment operation is atomic, look at the generated assembly:
add %l0,1,%l0
(may vary slightly depending on the assembly used)
But this. 1. That is why it is atomic.
When you assign a pre-increment to a local variable, these are at least two commands:
add %l0,1,%l0 st l0, [%fp-4]
This generates at least two commands and, therefore, is no longer atomic.
Please let me know if you have any questions!
source share