Nico wrote:
> Bob Hanson wrote:
>> pps. The following is more elegant and also works:
>>
>>   static Boolean[] testInit = new Boolean[1];
>>   private void initialize() {
>>     if (testInit[0] != null) {
[snip]
>> It takes advantage of the fact that static testInit[0] has THREE
>> possible values: null, false, and true.
>> This is what I'm going with for now.
>>
>
> That won't work in every situation :
> - thread 1 executes "if (testInit[0] != null)" and finds that it evals
> to false
> - thread 2 executes "if (testInit[1] != null)" and finds that it evals
> to false also
> - thread 1 goes on
> - thread 2 goes on
>
> You could try using a synchronization on a variable.

Nico is correct.

It is not possible to "roll your own" synchronization in a high level
language without having some type of atomic 'test-and-set' operation
support at a lower level.

Essentially all CPUs for the last 50 years have had this, but popular
high-level languages have not exposed this functionality. Java is arguably
the first commercially-successful-and-broadly-accepted language that
incorporates synchronization primitives into the language.

Per Nico's other message, my bug with 'initialize' is that it was marked
'synchronized' instead of 'syncronized static'.


Miguel



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

Reply via email to