开发者

OpenCL - atomic_cmpxchg

开发者 https://www.devze.com 2023-03-16 10:57 出处:网络
What does this function do??. I couldn\'t understand a thing from the OpenCL specification!! The code below is a snippet from spMV code.

What does this function do??. I couldn't understand a thing from the OpenCL specification!! The code below is a snippet from spMV code.

atomic_cmpxchg((__globa开发者_JAVA技巧l int*)loc, *((int*)&old), *((int*)&sum)) != *((int*)&old)


atomic_cmpxchg is "atomic compare and exchange". It implements an atomic version of the standard C99 ternary operation. For the code above it implies the atomic equivalent of the following:

p = *loc;
*loc = (p == *old) ? (*sum != *old) : p;

with the atomic_cmpxchg call returning p. The operation is atomic, this means that no other thread can read or write from loc until the transaction is completed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号