RE: JavaMemoryModel: Thread model algorithm.

From: David Holmes (dholmes@dltech.com.au)
Date: Tue Nov 18 2003 - 22:01:36 EST


Sylvia,

To put it in simple terms, the use of "if (!condition) wait()" is
wrong in any circumstances where the condition being waited upon could
have changed between the notification and the time when the waiting
thread actually acquires the monitor and proceeds under the assumption
that the condition holds.

This can occur:

a) when barging is possible (as per your example) - and barging is
indeed possible as per the spec and known to occur in many
implementations (lack of barging is an absolute performance killer);

b) when notifyAll is used rather than notify, but only one waiting
thread can act upon the changed condition;

c) probably some other circumstances too

I'm not going to enter a debate on the merits or otherwise of giving
preference to awoken waiters versus other threads. If your interested
see Peter Buhr et al's Monitor classification paper:

Peter A. Buhr, Michel Fortier, and Michael H. Coffin. Monitor
classification. ACM Computing Surveys, 27(1):63--107, March 1995.
http://citeseer.nj.nec.com/buhr95monitor.html

David Holmes

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



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