B
Bakul Shah
Guest
On 6/24/13 5:03 AM, Eric Wallin wrote:
a counter at location X? A reads X and finds it contains 10. But
before it can write back 11, B reads X and finds 10 and it too
writes back 11. Now you've lost a count. Can this happen in your
design? If so you need some sort of atomic update instruction.
Consider a case where *both* thread A and B want to incrementOn Monday, June 24, 2013 3:24:44 AM UTC-4, Tom Gardner wrote:
Consider trying to pass a message consisting of one
integer from one thread to another such that the
receiving thread is guaranteed to be able to picks
it up exactly once.
Thread A works on the integer value and when it is done it writes it to location Z. It then reads a value at location X, increments it, and writes it back to location X.
Thread B has been repeatedly reading location X and notices it has been incremented. It reads the integer value at Z, performs some function on it, and writes it back to location Z. It then reads a value at Y, increments it, and writes it back to location Y to let thread A know it took, worked on, and replaced the integer at Z.
The above seems airtight to me if reads and writes to memory are not cached or otherwise delayed, and I don't see how interrupts are germane, but perhaps I haven't taken everything into account.
a counter at location X? A reads X and finds it contains 10. But
before it can write back 11, B reads X and finds 10 and it too
writes back 11. Now you've lost a count. Can this happen in your
design? If so you need some sort of atomic update instruction.