I have not read the list for some time, so I'm a little late. On Monday 12 November 2001 21:48, you wrote: > On Monday 12 November 2001 14:56, you wrote: > > On Mon, Nov 12, 2001 at 03:06:33PM -0500, Gianni Johansson wrote: > > > There are unlocked reads and writes of runningCount in several places. > > > This looks like a race condition to me. Remember that ++ and -- are > > > not guaranteed to be atomic. > > > > runningCount is volatile so you don't have to worry about ++ and -- > > Making an int volatile only guarantees that atomic operations will be > consistent across multiple threads, but ++ and -- are not atomic > operations.
The only thing that volatile garanties is that the compiler will not cache the variable in a register to gain performance. Therefore it will be written to memory. On single CPU and some SMP systems this means that another thread can see the change. On systems with many CPUs the memory model (ex. NUMA) often don't garantie that all CPUs can see the change without the program explicitly requests a consistent memory view. This is what synchronize does in Java. Volatile is ofcause usefull if you know what system a program should run on, but Freenet should run anywhere so volatile is not an option. For a more detailed explaination se this link: http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html _______________________________________________ Devl mailing list Devl at freenetproject.org http://lists.freenetproject.org/mailman/listinfo/devl
