RenderScript Atomic Update Functions

Overview

To update values shared between multiple threads, use the functions below.
They ensure that the values are atomically updated, i.e. that the memory
reads, the updates, and the memory writes are done in the right order.

These functions are slower than their non-atomic equivalents, so use
them only when synchronization is needed.

Note that in RenderScript, your code is likely to be running in separate
threads even though you did not explicitely create them. The RenderScript
runtime will very often split the execution of one kernel across multiple
threads. Updating globals should be done with atomic functions. If possible,
modify your algorithm to avoid them altogether.