On Wed, 14 Jun 2006 13:57:38 +0100, Matthew Toseland wrote: > On Wed, Jun 14, 2006 at 12:59:56PM +0300, Jusa Saari wrote: >> On Tue, 13 Jun 2006 20:34:05 +0100, Matthew Toseland wrote: >> >> > On Tue, Jun 13, 2006 at 10:26:55PM +0300, Jusa Saari wrote: >> >> What happens if the watchdog gets stuck too ? It has to synchronize >> >> with the watched thread sometimes to do its work, AFAIK. >> > >> > It just reads a variable. An int. Without synchronization. >> >> I hope that's a "volatile" variable ? > > Is that necessary?
Yes. It guarantees that the watchdog thread sees any updates made by the watched thread, instead of seeing a possibly stale value in local CPU cache. Not using "volatile" keyword in variable declaration is not an issue in an X86 platform, since the X86 architechture gives stricter cache coherency guarantees than Java Memory Model, but it's going to lead to really nasty bugs in any architechture that doesn't give them. Basically "volatile" guarantees that each thread will see the changes made by any other thread, without needing to synchronize. It also guarantees that longs and other larger-than-32-bit variables will be read and written atomically, but that doesn't matter for ints, obviously. Here's a bit more info - see the bottom of the page: http://g.oswego.edu/dl/cpj/jmm.html _______________________________________________ Devl mailing list [email protected] http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl
