What problems might arise when sharing an int between two threads?
- by Tobbe
Two threads accesses a shared int, x. What problems can arise from instruction reordering etc.
Thread 1:
x = 1;
Thread 2:
obj.f(x);
What would change if x is declarared volatile?
What would change if Thread 1 and Thread 2 runs on different cores?