RE: JavaMemoryModel: OT: Semantics for yield and sleep

From: Roly Perera (roly.perera@ergnosis.com)
Date: Wed Jan 09 2002 - 04:44:17 EST


> > I can't help but ask if the following is a legal transformation:
> >
> > thread.yield();
> > ==>
> > try {
> > thread.sleep(Long.MAX_VALUE);
> > }
> > catch (InterruptedException ex) {
> > thread.interrupt();
> > }
>
> Given that Java makes no guarantees of forward progress,
> isn't that a valid construct for a compiler to insert between
> any two instructions?

Indeed. And for the same reason a Java compiler can insert:

    while (true);

between any two statements, with the only crime being poor provision of
service. Since the Java spec makes no temporal claims whatsoever, I
don't see how Thread.yield() can be defined other than by appealing to
intuition.

It's not dissimilar to the way a Java compiler can insert:

    throw new OutOfMemoryError();

prior to any statement or expression which whose evaluation can complete
abruptly with an OutOfMemoryError, and still respect the semantics of
the language.

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:37 EDT