What's wrong here?

global
void check(int *lock, int i, int *p)
{
*p= lock[i];
}

global
void valuate(int *from, int *to, int *start, int *duration, int *earliest, int *lock)
{

while(1)
{
check<<<1,1>>>(lock,from[i],p);
if(*p==1)
{
break;
}

}
change<<<1,1>>>(earliest,to[i],from[i],start[i],duration[i],lock);

}

I see that the while loop runs in a continuous while loop ad doesn’t stop at all. Check function always reads the old value. How do I ensure the expected working of pointer p.

Device side kernel launches are asynchronous, just as host side kernel launches are.
So you need to call cudaDeviceSynchronize() between launching the inner kernel and testing it’s result.

I put cudaDeviceSynchronize() before check<<<1,1>>>(lock,from[i],p); but still gives me the same output. Any other way for it?

Put cudaDeviceSynchronize() after check<<<1,1>>>(lock,from[i],p); .