Fetch-and-add

Fetch-and -add is a term used in computer science, which describes a method for atomic modification of a memory region.

Operation

The process is use of a function call that is processed by the operating system implemented. The content of a memory cell is read out and overwritten in the same memory cycle, with a new value which is greater by 1. The advantage is that other processes can not change the value of the variable during this process. Inconsistencies and data loss are excluded. For the use of fetch-and -add an appropriate hardware support must be available.

Implementation

Example is to be given a possible implementation of the technique in the C programming language. Depending on the programming language, the call may differ.

Atomic << >> int FetchAndAdd ( old address value) {      int value = * old value;      * old value = value 1;      returnValue; } For this implementation a pointer to the memory cell to be changed is used (in this old value)

Demarcation from other methods

Besides fetch-and - add, there are other ways to grant exclusive access to storage areas. So it is sufficient for uniprocessor systems to prevent the execution of interrupts during memory content is changed by a process. On systems with multiple processors ( multicore architectures ) this approach is not sufficient.

A further alternative to fetch-and -add is Compare- and - swap.

332723
de