Etienne M. Gagnon wrote:

>On Fri, Feb 15, 2002 at 11:19:15AM +0100, Sascha Brawer wrote:
>
>>Hello,
>>
>>the implementations of java.util.Hashtable.size() and
>>java.util.Hashtable.isEmpty() merely access a single integer member
>>field.  Since accesses to integer variables are required to be atomic, I
>>think these two methods don't need to be synchronized. Do people agree?
>>(Yes, it's a micro-optimization).
>>
>
>I do not agree.  If I remeber correctly, this atomicity is only true
>of "volatile" variables.  Otherwise, you have no garantee that the
>integer value visible to one thread is the same as the one visible to
>another on a multiprocessor system.
>

You are correct that, without synchronization, the value for size could 
be seen differently by different CPUs at the same time. However, 
synchronizing is itself no guarantee of "thread safety" here. Even if it 
were synchronized the value could have been changed by another thread 
before getSize() returns, so it makes no difference either way. 
Hashtable and Vector (and the "synchronized" method modifier for that 
matter) are so bogus!

regards

Bryce.



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

Reply via email to