user manual code example race condition

Mark Evenson evenson at panix.com
Mon Mar 11 09:59:47 UTC 2019



> On Mar 11, 2019, at 06:38, dingd <ntysdd at qq.com> wrote:
> 
> this is recommended in the manual, it contains a race condition.
> 
> Interpreter interpreter = Interpreter.getInstance ();
> if ( interpreter == null ) {
> 	interpreter = Interpreter.createInstance ();
> }
> 
> getInstance and createInstance should be swapped.

Since both Interpreter.getInstance() and Interpreter.createInstance() are
methods synchronized on the same object monitor, I don’t see that there is a
race condition here.  Could you explain a little more about your reasoning
and/or experience with the race condition?

-- 
"A screaming comes across the sky.  It has happened before but there is nothing 
to compare to it now."








More information about the armedbear-devel mailing list