dead lock in cuda 7.5

I have the following code working fine in cuda 6.5,
bool leaveloop;
while (!leaveLoop) {
if (atomicExch(&lock, 1u) == 0u) {
//critical section
leaveLoop = true;
atomicExch(&lock,0u);
}
}
But when I try to run this code in cuda 7.5, this results in a dead lock.
The above code is a code snippet for a method in a class. And lock is an integer member of that class. And I created an array of objects in global memory.
Even if I launch a single block with 64 threads. The kernel also enters a dead lock.
Any help would be appreciated.

If lock is not initially initialized to 0 in a thread-safe way, the initial atomic check could always fail in an endless loop. That may or may not be a problem but it’s impossible to tell just seeing only your incomplete code snippet.

If you post minimal code example, ready to compile and run and show a deadlock it would help everyone to spot any issues.