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

From: Boehm, Hans (hans_boehm@hp.com)
Date: Wed Jan 02 2002 - 13:37:21 EST


> From: Jerry Schwarz [mailto:jschwarz@us.oracle.com]
> >Example 1:
> >Initially, volatile x = 0
> >
> >Thread 1:
> >while (x == 0) {
> > Thread.yield();
> > }
> >
> >Thread 2:
> >x = 1
>
>
> No I do not. Unless you impose some fairness requirement, there is no
> reason to believe that Thread 2 will ever run. I think the
> specification of
> yield requires that some other thread besides thread 1 will
> make progress,
> although even that is unclear. But unless the above are the
> only threads
> in the system there is no guarantee that thread 2 will run.
>
> Thread.yield is essentially a nop. In practical systems it is
> important,
> but from the point of view of the semantics of the Java it is a nop.
>
I agree with Jerry on this one. But I do think that if you replace Thread 1
by

int i;
while (x == 0) {
         Thread.sleep(++i);
         }

The result should terminate. Jerry, do you agree?

Hans
-------------------------------
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