understanding cuda memory reads

Hi everyone,

I have a simple question, but I’ve been stuck trying to find out what’s happening in this simple code. Forgive me if the problem is so obvious.
This is a code in a kernel with 1 block, 512 threads.

d_pointSize[0] = 4;

if (threadIdx.x < 50) {
d_frontStack[threadIdx.x*d_pointSize[0]+3] = -1;


if (threadIdx.x < 200) {
d_frontStack[threadIdx.x] = threadIdx.x;

I thought that the second write should overwrite the first memory write (-1)s. But it didn’t!
I’m so confused, why is it that some of the values in d_frontStack is still -1 when I print it out?
Is it something to do with how compiler manage memory accesses?

I thought that this should overwrite

I think I found the problem, it wasn’t in this code. I was synchronizing threads within a conditional!