[concurrency-interest] lock removal by compiler together with monitor-lock order rule

Peter Veentjer alarmnummer at gmail.com
Thu Nov 23 15:45:26 EST 2006


Or could it be ,that the lack of program order n the content of the
methods are the cause that piggybacking on synchronization doesn't
hold? If there is no program order, there is no piggybacking. This
means,there was no guaranteed behaviour in the first place.

On 11/23/06, Peter Veentjer <alarmnummer at gmail.com> wrote:
> I have a question about the compiler removing 'useless' synchronizations.
>
> eg:
>
> class Foo{
>     int value;
>
>    setValue(int value){
>        this.value = value;
>        synchronized(this){}
>    }
>
>    int getValue(){
>        synchronized(this){}
>        return value;
>    }
> }
>
> In this case the release of the lock in setValue and the get of the
> lock in getValue. provides safe 'piggy backing on synchronization' for
> the variable value.
>
> Removal of the synchronized blocks could change program behaviour. Is
> the compiler to allowed to remove these locks? My guess would be that
> this isn't allowed.
>


More information about the Concurrency-interest mailing list