> Miguel,
>
> What I meant was that the check for null array must be within the
> synchronized method initialize(), not in the constructor. So the two
> changes I effected were
>
> a) static added for initialize(), as per Nico's excellent observation
> b) remove check for null in the Geodesic3D constructor:
>
>
>     Geodesic3D(Graphics3D g3d) {
>       this.g3d = g3d;
>       initialize();
>     }
>
>   private static synchronized void initialize() {
>     if(vertexCounts != null)
>       return;
>     vertexCounts = new short[maxLevel];
>    ....
>  }
>
> Do you see what the problem was in having the check for null in the
> constructor itself?

Ahh ... I see ... I stand corrected.

I should not have set vertexCounts until the initialization was complete.

Per Nico's suggestion, it would be best to initialize with a temporary
variable and then set vertexCounts at the end, so as to avoid the call to
the initialize method.

In this particular case it does not really matter since there is only one
Geodesic3D object allocated per applet (if i recall correctly) ... but in
general that is the way that it should be done.


>
> Sorry about the confusion with constructors -- a book I have seemed to
> suggest that threads cannot yield while constructing, but that's
> obviously a misreading on my part.
>
> The problem was definitely in the missing static keyword, which Nico
> found... and the misplaced check for the start of initialization, which
> must appear ONLY within the synchronized method itself, not allowing a
> bypass of that synchronization. That's because if a second thread is
> allowed to bypass initialize() and not sync there, waiting for the first
> thread to complete, then it can skip right to code in Isosurface that
> requires those normals prior to the first thread completing the
> initialization. Right?

Correct.


Miguel



_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to