How to guarantee write operation before read operation in fragment shader?

I’m trying to store primitive list per voxel grid(3D).

Primitive List Index Map (PLIM) : the index of primitive list is stored in 3D (per voxel grid).
Primitive Counts Map (PCM) : primitive counts is also stored in 3D (per voxel grid).
Primitive Lists Map (PLM): primitive lists are stored in 2D (x : index of primitive list, y : primitives in the primitive list).
*(that means primitive lists are stored in like sparse octree but primitive counts & index of primitive lists are stored in octree.)

Now we can find primitive list at any voxel location.
First, we can find index of primitive list by lookup PLIM at the voxel location.
Second, we can find primitive list in PLM using index of primitive list.
Finally, we can iterate primitives in PLM using primitive counts in PCM at the voxel location.

Here is my code summary in fragment shader after voxelizing from rasterization

int currentPrimitiveCounts = ImageAtomicAdd(PCM, coords);
if (currentPrimitiveCounts == 0)
{
    int indexOfPrimitiveList = int(atomicCounterIncrement(IndexOfPrimitiveListAtomicCounter));//Atomic counter gives index of primitive list
    imageStore(PLIM,coords,indexOfPrimitiveList);//-----(1)
}
//synchronization : wait for indexOfPrimitiveList to be saved from another thread
while(imageLoad(PLIM,coords).r == -1);//---(2) $$this code generates infinite loop$$
//store primtive data
int indexOfPrimitiveList=imageLoad(PLIM,coords);
ivec2 PLMcoords= ivec2(indexOfPrimitiveList, currentPrimitiveCounts);
imageStore(PLM,PLMcoords,primitiveData);

while(imageLoad(PLIM,coords).r == -1)
this code generates infinite loop (maybe compiler optimization…?)
how to guarantee my write operation(1) before read operation(2)?

It can be solved by dividing into two passes, but I want to implement as one pass because I want to avoid overhead of voxelizing step twice.

I solved it by modifying imageLoad to imageAtomicCompSwap

//while(imageLoad(dst,coords)==-1))
while(imageAtomicCompSwap(dst,coords,-99999,-99999)==-1)

Now imageAtomicCompSwap run as atomic read operation.