Memory locking?
Philldapill
Posts: 1,283
I've got an ADC running all the time in a single cog. What it does is, it gathers 100 samples, then averages them and stores the average in a variable. The ADC is actually an object, so it has a method of retrieving the average variable. The main cog accesses this variable through ADC.getAverage. It is totally unsynched to the other cog.
I was wondering if there could ever be a conflict where the ADC cog is writing the value into the variable while the main cog is trying to retrieve it. Could this be a problem? Oh, this is all in spin, btw.
I was wondering if there could ever be a conflict where the ADC cog is writing the value into the variable while the main cog is trying to retrieve it. Could this be a problem? Oh, this is all in spin, btw.
Comments
That would not be the case if the variable were being written to not as a single word or long, but written a byte at a time. In that case a read could get a value where one byte had changed and the other three had not which would give a wrong result.
Likewise you could have problems with side-effects ...
average := ( ++average + latest ) / total ' meaningless code, just an example
Here the ++average will alter the shared value which could be read before the final value for average was calculated and written out.
All easy enough to avoid, so as long as none of these occur you'll be okay.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔