On 05/16/2014 05:22 PM, Paul Sandoz wrote:
On May 16, 2014, at 5:05 PM, Remi Forax <fo...@univ-mlv.fr> wrote:
On 05/16/2014 01:56 PM, Tobias Hartmann wrote:
Hi,
thanks to everyone for the feedback.
Is it sufficient then to use synchronized (lambdaForms) { ... } in
setCachedLambdaForm(..) and a normal read in cachedLambdaForm(..)?
Thanks,
Tobias
no, it's not,
The memory model doesn't guarantee that a normal read will see that another
thread has changed the array item,
the normal read may always see null.
You need a synchronized block around the normal read.
I don't think that is required since the pattern is:
form = cachedLambdaForm(which);
if (form != null) return form
...
form = /new form/
...
form = setCachedLambdaForm(which, form);
return form;
and the setCachedLambdaForm will, within it's the synchronized block, first
perform a read to check if there is already a non-default value present.
Paul.
Ok, got it,
it should work :)
cheers,
RĂ©mi