cuda locks code example
Example: cuda locks
//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);
}
}