I declare array like that private double[] array = new double[length]. Is it safe to update this array items in one thread and read in another thread? Will I have up to date value?
Note i do not enumerate array. I only access its items by index.
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.
Volatile does not guarantee freshness of a value. It prevents some optimizations, but does not guarantee thread synchronization.
Double is not guaranted to be updated atomically. So updating/reading arrays of doubles without synchronization will not be thread safe at all wit or without volatile as you may read partially written values.