Previous | Next --- Slide 7 of 46
Back to Lecture Thumbnails
ycp

In functionality atomicSum is the same as if you used a lock, but what is the difference in latency?

kayvonf

Yes. You can think of atomicAdd to operate like this.

void atomicAdd(int* addr, int value) {
  lock(myLockForAddr);
  *addr+=value;
  unlock(myLockForAddr);
}

Of course, you wouldn't actually have a lock per memory address, that would be crazy! So atomicAdd is typically a primitive that has direct hardware support. (e.g., an atomicAdd instruction)