[OT] Java volatile broken? [was Java/J2EE and the future..]
Mark Bucciarelli <mark-kYkyRIBsPJS5azolltMz9laTQe2KTcn/@public.gmane.org> Fri, 23 Apr 2004 12:43:29 -0400
| Newsgroups | gmane.linux.debian.devel.nonprofit |
|---|---|
| Organization | Hubcap Consulting |
| Message-ID | <[email protected]> |
On Wednesday 21 April 2004 2:24 pm, Chris wrote: [...] > I was actually thinking about writing a lengthy > analysis/advocacy essay series regarding areas where Open Source is > weak today and what can be done to improve the situation. Java will > be one of many topics. Regarding the general topic of Java, this morning I read some interesting stuff from Bruce Eckel's keynote at the last Python Conference [1]. Apparently, there is an issue with the volatile keyword in JDK's prior to 1.5. <quote> The examples he was working on for his Thinking in Java book were working (i.e. failing) in a dual processor box but he could not reproduce them on a single processor box. This is bad ... The cache in a multi processor box is not "flushed" (he thinks synchronised is a better term -- invalidation is probably better) - the temptation of the cpu to read a local variable is to read it from the cache - the hardware has to be aware that it has to fetch the real value from main memory - a very difficult thing to get correct. Discussion of read and write memory barriers (also known as a "fence".) Only now in JDK 1.5 does the volatile keyword correctly uses barriers. </quote> This is hard to believe, given all the SMP boxes running big Java apps, but there ya go. It would be interesting to get a test case from him, and see if it works on free software. :) [1] http://www.sauria.com/~twl/conferences/pycon2004/20040326/Bruce Eckel Keynote.txt -- Mark Bucciarelli, www.hubcapconsulting.com GNU/Linux user #266,902 at http://counter.li.org