What problems might arise when sharing an int between two threads?

Posted by Tobbe on Stack Overflow See other posts from Stack Overflow or by Tobbe
Published on 2010-04-17T17:20:40Z Indexed on 2010/04/17 17:23 UTC
Read the original article Hit count: 220

Filed under:

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?

© Stack Overflow or respective owner

Related posts about c++