I know that compound operations such as i++ are not thread safe as they involve multiple operations.
i++
But is checking the reference with itself a t
Regarding the weird behaviour:
Since the variable a is not marked as volatile, at some point it might value of a might be cached by the thread. Both as of a != a are then the cached version and thus always the same (meaning flag is now always false).
a
volatile
a != a
flag
false