Say I have a single floating point number called result equal to 0 and two threads, one thread adds 4 and the other subtracts 2. Is there any possibility that result will be equal something other then 2 afterwards?
If you want a more concrete example I ask this question because of a project I'm working on. Basically I'm simulating a network of neurons and I want to distribute the neurons among multiple threads so it runs faster.
Every thread is responsible for it's own group of neurons and at each time step of the simulation all threads calculate the voltage of their neurons and see if any neurons have exceeded a threshold, then they run into a barrier and wait for all the threads to catch up.
Then the voltages of any neurons connect to the neurons that exceeded the threshold are then added to or subtracted from depending on the strength of the connection. It's this step I worry about because two threads could try to change the voltage of the same neuron at the same time. I think I know a way around this but I wondered if things are fine the way they are, since the threads are adding or subtracting values as opposed to assigning values.
After this the threads run into the same barrier as before and wait for each other before starting the next time step.