Ao I am dealing with the following situation. I want all my threads to do a loop until none of them reaches a certain "if", so I use a global variable that stores 0 and when the if statement is reached that variable becomes 1.
The problem is that at the end of the loop I do a barrier to synchronize all the threads( in my case I just have 4) and only does that reached the if have the value of the global variable 1, the others have it 0.
How can that be? How can a global variable have different values in different threads?