On 26/05/2010, Konstantin Kolinko <knst.koli...@gmail.com> wrote: > 2010/5/26 sebb <seb...@gmail.com>: > > >> - private int removed = 0; > >> + private volatile int removed = 0; > > > > Volatile ensures correct publication across threads, but does not > > solve the lost-update problem. > > > > >> removed++; > > The above line can suffer from a lost update as the increment is not > atomic. > > > > > The "removed" variable is only checked whether it is zero or some > positive value. So, the actual value of the variable before the > increment operation is irrelevant. It could be written as "removed = > 1;" and assignment is atomic.
In that case, why not do so - or make it a boolean? > Are there any observable consequences? If they are, you may file an issue. A brief scan of the code suggests not, unless it is possible for the counter to overflow. But it is confusing to have a method called incrementRemoved() and a corresponding counter which is actually being used purely as a flag. May I suggest adding a comment to document this for future maintainers? > Best regards, > > Konstantin Kolinko > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org