N
neuneudr
Hi,
imagine that for whatever reason I decide *not* to use an
AtomicLongArray and go with a long[] (the reason is
actually that I want to understand what's going on).
public static final long[] ref = new long[42];
Do the following guarantee the correct visibility
when accessing the elements of the array :
From one thread :
synchronized (ref) {
ref[0] = 3;
}
and from another thread, later :
synchronized (ref) {
long val = ref[0]; // Am I guaranteed to get back '3'
here ?
}
Basically my question is : seen that array elements cannot
be declared volatile *and* that I want to use arrays, how
should I proceed if I want thread-safe behavior when
modifying/reading my array ?
imagine that for whatever reason I decide *not* to use an
AtomicLongArray and go with a long[] (the reason is
actually that I want to understand what's going on).
public static final long[] ref = new long[42];
Do the following guarantee the correct visibility
when accessing the elements of the array :
From one thread :
synchronized (ref) {
ref[0] = 3;
}
and from another thread, later :
synchronized (ref) {
long val = ref[0]; // Am I guaranteed to get back '3'
here ?
}
Basically my question is : seen that array elements cannot
be declared volatile *and* that I want to use arrays, how
should I proceed if I want thread-safe behavior when
modifying/reading my array ?