On Fri, 15 Feb 2002, Artur Biesiadowski wrote:
> If you can show me an example, where having isEmpty()/size() 
> synchronized _guarantees_ anything with fully preemptive threading, 
> which is not guaranteed with unsynchronized version, then let it be your 
> way. But I think that no such example can be given (but I would be happy 
> to be proven wrong, as this would mean I do not understand some basic 
> stuff with java threading).

Your points have merit... calling isEmpty() without synchronizing isn't
very useful.  But it still has side effects, like a memory barrier.

I'm wary of removing any occurrences of synchronization as an
optimization, including things like "synchronized (this) {}", because of
the implied barrier semantics.  Consider:

Hashtable ht;
a = 0;
b = 0;
...
a = 1;
ht.size();
b = 1;

and in another thread:

synchronized (this) {
  System.out.println(a + "," + b);
}

can this ever print 0,1?

Jeff


_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to