cuda lock code example
Example: cuda lock
//d_lock must be initialized to 0
bool success = false;
while(!success) {
if (atomicCAS(&d_lock[i], 0, 1) == 0) {
//critical section
success = true;
atomicExch(&d_lock[i], 0);
}
}
//d_lock must be initialized to 0
bool success = false;
while(!success) {
if (atomicCAS(&d_lock[i], 0, 1) == 0) {
//critical section
success = true;
atomicExch(&d_lock[i], 0);
}
}