Hi Simon,
As pointed out earlier by someone else, p here is not defined as class variable. Secondly, if you define i as volatile, that will force each thread to refresh its local copy of i before it actually tries to modify i. So Try following code.
public class Unstable implements Runnable {
private int p = 0;
private volatile int i = 0;
public void run() {
for(; i <= 10; i++) {
System.out.println("Thread " + Thread.currentThread().getName() + " i=" + i + " p=" + p++);
}
}
}