This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Double checked locking and GCJ?
- From: Andrew Haley <aph at redhat dot com>
- To: Martin Egholm Nielsen <martin at egholm-nielsen dot dk>
- Cc: java at gcc dot gnu dot org
- Date: Tue, 28 Jun 2005 11:35:25 +0100
- Subject: Re: Double checked locking and GCJ?
- References: <d9r853$5vn$1@sea.gmane.org>
Martin Egholm Nielsen writes:
> Hi there,
>
> Sorry for bringing up what may be the most tedious thread ever. But does
> "double checked locking" work with GCJ:
>
> // Works with acquire/release semantics for volatile
> // Broken under current semantics for volatile
> class Foo {
> private volatile Helper helper = null;
> public Helper getHelper() {
> if (helper == null) {
> synchronized(this) {
> if (helper == null)
> helper = new Helper();
> }
> }
> return helper;
> }
> }
>
> (From:
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html)
I think it depends on the memory model of the particular hardware on
which the program is executing. For it to be otherwise, every access
to a volatile would require a full memory barrier, and I don't think
we do that.
Andrew.