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

From: Boehm, Hans (
Date: Mon Dec 31 2001 - 17:13:11 EST

> -----Original Message-----
> From: Bill Pugh []
> In finishing up our writeup on fairness, I think we need to guarantee
> some semantics for Thread.yield() and Thread.sleep().
> Specifically, either operation should have the semantics that with
> some finite probability, some other eligible thread of equal or
> higher priority is allowed to execute at least one instruction.
I'm not completely sure I understand what you want.
But to me, Thread.yield() and Thread.sleep(<sufficiently large>) are
fundamentally different.

> This guarantee will ensure that both of the following two examples
> terminate, while without the guarantee they can both fail to
> terminate.
> Example 1:
> Initially, volatile x = 0
> Thread 1:
> while (x == 0) {
> Thread.yield();
> }
> Thread 2:
> x = 1
To me, the guarantee that this terminates isn't very interesting. If I also
have threads 3 and 4, which are identical to 1 and 2 respectively, except
that they access shared variable y, then the resulting program may no longer
terminate, even with the guarantee. Thread 1 may always yield to thread 3
and vice-versa. Thus if I prove termination on small programs the proof may
be invalidated by adding more threads, which seems to make it very hard to
use the property.

I really want to know that if N out of M threads call Thread.sleep(...) with
increasing arguments then eventually one of the other (M - N) threads will

Bill - Will that do for your purposes? Jerry - Does this address your

JavaMemoryModel mailing list -

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