User`s guide

Developing an Application [3]
3.3.1 Synchronizing Data Using int_fetch_add
Use the int_fetch_add generic function to synchronize updates to data that
represents shared counters without using locks. This function has the following
signature:
int_fetch_add (&v, i)
The int_fetch_add function provides access to the underlying atomic
int_fetch_add machine operation. This function atomically adds i to the value at
address v, stores the sum at v, returns the original value of v, and sets the state bit to
full. In short, it does the following, as a single atomic operation:
t = v; v = v+i;
return t;
You can use int_fetch_add to identify the last of a group of threads to complete
a task, to partition data into groups, or to maintain a stack or queue index.
3.3.2 Avoiding Deadlock
Using sync variables can introduce deadlock into a program if, when the program
executes, threads attempt to do more reads than writes to a sync variable. When
you are trying to determine how many read operations the program performs, it is
important to remember that every reference to a sync variable results in a separate
read of that variable, even when the references occur in the same source code
statement. For example, in the following cases:
Your program references a sync variable two or more times on the right side of an
assignment statement. For example, if x$ is a sync variable:
sum = x$ + x$;
Your program references a sync variable two or more times in a conditional test.
For example, if x$ is a sync variable:
if ((x$ >= 10)&&(x$ <= 100)){}
S247920 25