Unexpected GLSL behaviour with atomic counters

GLSL_Thing.tox (950 Bytes)

I have a glsl compute shader with two atomic counters, and I increment them both one after the other.
For debugging I have set the shader to output the difference between the counters. I would expect this to be all black, as each counter should have the same value, but this is not the case. I see red stripes. I have observed that the width of the red stripes is the same as local_size, and also the difference in values occurs in multiples of local_size as well. I’m probably just misunderstanding how atomic counters are supposed to work but i can’t figure out why this is happening. Any ideas? See attached file

layout (binding = 0) uniform atomic_uint incounter;
layout (binding = 0) uniform atomic_uint outcounter;

layout (local_size_x = 16, local_size_y = 1) in;
void main()
{
	ivec2 mycoord = ivec2(gl_GlobalInvocationID.xy);

	uint inc = atomicCounterIncrement(incounter);
	uint outc= atomicCounterIncrement(outcounter);

	imageStore(mTDComputeOutputs[0], mycoord, TDOutputSwizzle(vec4(float(inc)-float(outc),0.0,0.0,1.0)));
}

There is no guarantee of the order these instructions will be executed between threads. For example in the case of two threads

Thread1:
inc1 = atomicCounterIncrement(incounter)
// inc1 == 0

Now thread2 executes:
inc2 = atomicCounterIncrement(incounter)
// inc2 == 1
outc2 = atomicCounterIncrement(outcounter)
// outc2 == 0

Now thread1 excutes again:
outc1 = atomicCounterIncrement(outcounter)
// outc1 == 1

So inc1 == 0 and outc1 == 1 for thread 1
And inc2 == 1 and outc2 == 0 for thread 2