Read–modify–write explained

In computer science, read–modify–write is a class of atomic operations (such as test-and-set, fetch-and-add, and compare-and-swap) that both read a memory location and write a new value into it simultaneously, either with a completely new value or some function of the previous value. These operations prevent race conditions in multi-threaded applications. Typically they are used to implement mutexes or semaphores. These atomic operations are also heavily used in non-blocking synchronization.

Maurice Herlihy (1991) ranks atomic operations by their consensus numbers, as follows:

It is impossible to implement an operation that requires a given consensus number with only operations with a lower consensus number, no matter how many of such operations one uses.[2] Read–modify–write instructions often produce unexpected results when used on I/O devices, as a write operation may not affect the same internal register that would be accessed in a read operation.[3]

This term is also associated with RAID levels that perform actual write operations as atomic read–modify–write sequences.[4] Such RAID levels include RAID 4, RAID 5 and RAID 6.

See also

Notes and References

  1. http://www.ddj.com/embedded/210604448?pgno=3 "Writing Lock-Free Code: A Corrected Queue"
  2. Herlihy . Maurice . Wait-free synchronization . ACM Trans. Program. Lang. Syst. . 13 . 1 . January 1991 . 124–149 . 2007-05-20 . 10.1145/114005.102808 . 10.1.1.56.5659 . 2181446 .
  3. http://techref.massmind.org/techref/readmodwrite.htm Massmind: "The read–modify–write problem"
  4. Web site: Basic RAID Organizations . https://web.archive.org/web/20210224160746/http://www.ecs.umass.edu/ece/koren/architecture/Raid/basicRAID.html. 2021-02-24 . 2013-10-04 . umass.edu.