You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Peter Donald <do...@apache.org> on 2001/10/22 02:31:36 UTC
[Torque] DCL doesn't work
Hi,
I noticed you were using double checked locking in one class. Unfortunately
due to javas memory model this is not an approach that works. In short DCL is
a broken pattern and if you want the full commentry there was discussion of
this approach on the Javaworld site (do a search for Brian Goetz + DCL).
The probelm essentially comes down to java allowing extensive operation
reordering that could result in the value being assigned to value before it
is fully initialized and thus a check for null would pass but the actual
object would not be ready for use. Heres a patch to correct this
--
Cheers,
Pete
*------------------------------------------------------*
| "Computers are useless. They can only give you |
| answers." - Pablo Picasso |
*------------------------------------------------------*
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org
Re: [Torque] DCL doesn't work
Posted by Jon Stevens <jo...@latchkey.com>.
on 11/14/01 10:19 AM, "Daniel Rall" <dl...@finemaltcoding.com> wrote:
> What does everyone else think of this diff from Peter? I'm unsure of
> its necessity in this situation.
+1
Just take out the //DCL comments because the patch removes the problem. :-)
-jon
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [Torque] DCL doesn't work
Posted by Daniel Rall <dl...@finemaltcoding.com>.
Peter Donald <do...@apache.org> writes:
> On Mon, 22 Oct 2001 11:04, Daniel Rall wrote:
> > Peter Donald <do...@apache.org> writes:
>> > I noticed you were using double checked locking in one class.
>> > Unfortunately due to javas memory model this is not an approach that
>> > works. In short DCL is a broken pattern and if you want the full
>> > commentry there was discussion of this approach on the Javaworld site (do
>> > a search for Brian Goetz + DCL).
>> >
>> > The probelm essentially comes down to java allowing extensive operation
>> > reordering that could result in the value being assigned to value before
>> > it is fully initialized and thus a check for null would pass but the
>> > actual object would not be ready for use. Heres a patch to correct this
>>
>> We're aware of DCL issues. Patch was not attached, and I'm not sure
>> which class you're referring to.
>
> Ooops - my excuse is that I hadn't yet had my daily dose of caffeine ... err
> coffee ;)
What does everyone else think of this diff from Peter? I'm unsure of
its necessity in this situation.
Index: Torque.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
retrieving revision 1.39
diff -u -u -r1.39 Torque.java
--- Torque.java 2001/11/13 01:10:27 1.39
+++ Torque.java 2001/11/14 18:01:10
@@ -401,23 +401,19 @@
}
}
- // Quick (non-sync) check for the map we want.
- DatabaseMap map = (DatabaseMap) dbMaps.get(name);
- if (map == null)
+ //DCL is broken !!!!!!!!!!!!!!!
+ //We can not use it in a multithreaded environment.
+ //Thus we are forced to go through synchronizaed section
+ synchronized (dbMaps)
{
- // Map not there...
- synchronized (dbMaps)
+ DatabaseMap map = (DatabaseMap) dbMaps.get(name);
+ if (map == null)
{
- // ... sync and look again to avoid race condition.
- map = (DatabaseMap) dbMaps.get(name);
- if (map == null)
- {
- // Still not there. Create and add.
- map = initDatabaseMap(name);
- }
+ // Still not there. Create and add.
+ map = initDatabaseMap(name);
}
+ return map;
}
- return map;
}
/**
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [Torque] DCL doesn't work
Posted by Peter Donald <do...@apache.org>.
On Mon, 22 Oct 2001 11:04, Daniel Rall wrote:
> Peter Donald <do...@apache.org> writes:
> > I noticed you were using double checked locking in one class.
> > Unfortunately due to javas memory model this is not an approach that
> > works. In short DCL is a broken pattern and if you want the full
> > commentry there was discussion of this approach on the Javaworld site (do
> > a search for Brian Goetz + DCL).
> >
> > The probelm essentially comes down to java allowing extensive operation
> > reordering that could result in the value being assigned to value before
> > it is fully initialized and thus a check for null would pass but the
> > actual object would not be ready for use. Heres a patch to correct this
>
> We're aware of DCL issues. Patch was not attached, and I'm not sure
> which class you're referring to.
Ooops - my excuse is that I hadn't yet had my daily dose of caffeine ... err
coffee ;)
--
Cheers,
Pete
-----------------------------------------------------------
If your life passes before your eyes when you die,
does that include the part where your life passes before
your eyes?
-----------------------------------------------------------
Re: [Torque] DCL doesn't work
Posted by Daniel Rall <dl...@finemaltcoding.com>.
Peter Donald <do...@apache.org> writes:
> I noticed you were using double checked locking in one class. Unfortunately
> due to javas memory model this is not an approach that works. In short DCL is
> a broken pattern and if you want the full commentry there was discussion of
> this approach on the Javaworld site (do a search for Brian Goetz + DCL).
>
> The probelm essentially comes down to java allowing extensive operation
> reordering that could result in the value being assigned to value before it
> is fully initialized and thus a check for null would pass but the actual
> object would not be ready for use. Heres a patch to correct this
We're aware of DCL issues. Patch was not attached, and I'm not sure
which class you're referring to.
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org