开发者

OpenCL - atomic_cmpxchg

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜