Suppose I have an array defined as follows:
volatile char v[2];
And I have two threads (denoted respectively by A, B) controlling the v array. If I guarantee that A, B use different indexes at any time, that is, if A now manipulates v[i] , then B does nothing or does not manipulate v[1-i] . I wonder if synchronization is needed for this situation?
I mentioned this question , however I think it is limited to Java. The reason I ask this question is because I am struggling to deal with a strange and rare mistake in a large project for several days, and so far the only reason I could explain this error , lies in the fact that synchronization is necessary for the above manipulation. (Since error is very rare, it is difficult for me to prove whether my hypothesis is true)
Edit: both reading and changing are possible for v .
c ++ c arrays multithreading synchronization
ACcreator Sep 06 '14 at 5:16 2014-09-06 05:16
source share