Atomic operations (increment, decrement, compare exchange?)

295 views
Skip to first unread message

Jeff Ward

unread,
Nov 28, 2011, 10:01:36 PM11/28/11
to native-cli...@googlegroups.com
Hi Naclers!

Are there any built in atomic operations available for NaCL yet?  Things like win32's InterlockedIncrement, InterlocedDecrement, or InterlockedCompareExchange?

--
Jeff

Derek Schuff

unread,
Nov 29, 2011, 1:07:46 AM11/29/11
to native-cli...@googlegroups.com
Hi Jeff,
It depends on what you mean by "built in." There are plenty of ways to get atomic operations, in various libraries (e.g. the examples you gave are in the win32 library), or built right into the compiler. Win32 is obviously not available in NaCl, but the gcc compiler has several builtin functions for atomic operations: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html That set includes interlocked increment/decrement (either __sync_fetch_and_add or __sync_add_and_fetch can be used for atomic increment) and compare and swap, and a few others. 
-Derek


--
Jeff

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To post to this group, send email to native-cli...@googlegroups.com.
To unsubscribe from this group, send email to native-client-di...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/native-client-discuss?hl=en.

Victor Khimenko

unread,
Nov 29, 2011, 3:20:15 AM11/29/11
to native-cli...@googlegroups.com
On Tue, Nov 29, 2011 at 10:07 AM, Derek Schuff <dsc...@google.com> wrote:
Hi Jeff,
It depends on what you mean by "built in." There are plenty of ways to get atomic operations, in various libraries (e.g. the examples you gave are in the win32 library), or built right into the compiler. Win32 is obviously not available in NaCl, but the gcc compiler has several builtin functions for atomic operations: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html That set includes interlocked increment/decrement (either __sync_fetch_and_add or __sync_add_and_fetch can be used for atomic increment) and compare and swap, and a few others. 

Proper link is http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Atomic-Builtins.html , but it only fixes problem with NAND operation...

Jeff Ward

unread,
Nov 29, 2011, 11:43:58 AM11/29/11
to native-cli...@googlegroups.com
Thanks guys, exactly what I needed.

And these work as expected in NaCL?

Derek Schuff

unread,
Nov 29, 2011, 11:51:19 AM11/29/11
to native-cli...@googlegroups.com
Yes, the atomic gcc builtins all work in NaCl
Reply all
Reply to author
Forward
0 new messages