RE: JavaMemoryModel: Guaranteed semantics for Thread.yield()

From: Roly Perera (roly.perera@ergnosis.com)
Date: Mon Dec 31 2001 - 14:04:50 EST


Bill Pugh wrote:

> The problem is that putting specific time bounds or other qualitative
> numeric guarantees into a specification is too difficult. Whatever
> values we give now might not be appropriate in 20 years. Also, what
> if you want to implement a JVM as part of the Long Now project
> (http://www.longnow.org/), which might execute only one bytecode/hour?

Sure. I wasn't suggesting that quantitative temporal constraints of any
kind would be appropriate to the JVMS. On the contrary, I was curious
about from whence *qualitative* guarantees of the kind you describe -
must happen "eventually" - derive their meaning. (I'm assuming there's
some kind of theory of fairness or similar?)
 
> Saying that it must eventually terminates means that a compiler can't
> transform example 2 from
>
> Example 2:
> Initially, x = 0 (x is non-volatile in this example).
>
> Thread 1:
> int r1;
> do {
> Thread.yield();
> synchronized(this) {
> r1 = x;
> }
> } while (r1 == 0);
>
> Thread 2:
> synchronized(this) {
> x = 1
> }
>
> to
>
> Illegal modification of Example 2:
> Initially, x = 0 (x is non-volatile in this example).
>
> Thread 1:
> int r1;
> synchronized (this) {
> do {
> Thread.yield();
> r1 = x;
> } while (r1 == 0);
> }
>
> Thread 2:
> synchronized(this) {
> x = 1
> }
>
> which is all we are trying to prevent.

I understand that this is what you are trying to prevent. I'm just
unsure as to the procedure for determining whether this transformation
has in fact been carried out. I don't see how (with the fairness rules
as described) it is ever possible to be certain that the particular
transformation above has actually been made.

- Roly

Roly Perera
Ergnosis Ltd

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:36 EDT