jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: Why do Functions that only have values as instance variable synchronize execute ?
Date Thu, 16 Oct 2014 16:06:18 GMT
On 16 October 2014 16:32, Vladimir Sitnikov <sitnikov.vladimir@gmail.com> wrote:
>>JMeter was originally written for Java
>>1.4 (or earlier); I think volatile did not offer the safe publication
>>guarantee then.
>
> That is correct, however see below.
>
>> No, because the Java Memory Model only guarantees safe publication of
>> a mutable field if the writer and reader synchronize on the same lock.
>
> This is plain wrong. Here are a couple of "whys":
> 1) There are lots of cases when "safe publication" is guaranteed without
> synchronization and/or volatiles (thread start/stop, final fields, etc)

OK, perhaps "only" is too strong.
However these are external (*) to the class; changes to the app design
may invalidate any such assumptions.

(* apart from final, but I did write "mutable fields", which excludes final)

> 2) Just synchronization on the same lock is not sufficient (see
> "synchronizes-with" in the JMM)

I don't follow that.

> See 17.4.5 of the java language specification [1]: A call to start() on a
> thread happens-before any actions in the started thread.

Yes, I knew that.

> Since JMeterThreads are started after all the variables are set/cloned (as
> in program order of the main thread), then you are guaranteed to see a safe
> view when running in JMeterThread.

OK, but as already written, that is something over which the class has
no control.

Since it is something that could potentially change, this assumption
would need to be carefully documented

> This is safe even without volatiles and synchronization, even in java 1.4.
>
> [1] http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5
>
> Vladimir Sitnikov

Mime
View raw message