Is the != check thread safe?

后端 未结 8 1989
醉酒成梦
醉酒成梦 2021-01-29 18:56

I know that compound operations such as i++ are not thread safe as they involve multiple operations.

But is checking the reference with itself a t

8条回答
  •  逝去的感伤
    2021-01-29 19:21

    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).

提交回复
热议问题