hi all!

> -----Original Message-----
> From: Brian Goetz [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, January 27, 2001 3:15 AM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: FW: Thread-safety
> [...]
> Assuming jspx_init() might create an object (what else would 
> an init() 
> routine do?), the problem is that your initial reference of 
> jspx_inited is 
> unsynchronized.  Supposed thread A is inside the synchronized 
> block.  Thread B is about to execute "if (_jspx_inited == 
> false).  The 
> compiler/cache/memory CAN make it appear to thread B that 
> jspx_inited has 
> been set to true before all the instructions corresponding to 
> jspx_init() 
> have executed.

but as far as i can see this is not a problem:

1. the inner block does not get executed, which is exactly what i want.  if
thread a is initializing then we do not want to have other threads doing the
same stuff again.  (in fact - not considering exceptions which might let the
initialization fail - the earlier the flag gets switched the better.  but,
clearly, keeping exceptions in mind the flag should be set only if the
initialization succeeds.  although i doubt whether a second try will
succeed...)

2. the "real" check is done inside the synchronized block and by the time
the lock is aquired by the second thread this real check should work on the
real data.

i am not too deep into JVM mechanics but one general rule for optimizations
is that they are not allowed to change the execution semantics of a piece of
software.  so if there are some reorderings then they must not change the
semantics - otherwise i would seriously question them.

regards

        robert

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to