witcher01.github.io

Built-in functions for atomic memory access

Using a semaphore requires an atomic operation, so that a deadlock cannot occur. The Intel Itanium Processor-specific Application Binary Interface specifies some built-ins that are atomic operations… There are built-ins for a few functionalities, but these are the most imporant:

The first of the two can be called in gcc by using the following built-in functions:

Type 1 and 2 are only different in the sense, that Type 1 returns the value that had previously been in memory, and Type 2 returns the new value.

The second of the two are atomic operations for comparing and swapping

These functions take 3 arguments:

These functions compare the current value of ptr to oldval and if they are the same, newval is being written to ptr… The two types are different in the way that the first type returns a bool if the comparison is successful and newval is written into ptr and the second type returns the content of ptr before the operation.