Is correct to divide the following statements:
int v = ++j;
as:
- read j value (atomic);
- increment by 1 the value read (NON
atomic possibly interference by
other thread); - write the adding result to i
(atomic); - write i into v (atomic)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes,
int(or smaller datatypes) read/write/arithmetic operations are atomic. References (read/write) are also atomic, regardless of whether it’s 32-bit or 64-bit.However, operations on 64-bit
longanddoublemay not be atomic.JLS 17.7 Non-atomic Treatment of
doubleandlongNote that neither pre- nor post- increment/decrement operators themselves are atomic, not even on
intorbyte: the read/write/arithmetic operations happens in distinctly separate steps.See also