Read-modify-write

读-修改-写(read-modify-write)是计算机科学中的一个原子操作(atomic operation,类似的还有test-and-set, fetch-and-add, compare-and-swap等),操作过程是读一个内存位置(或IO端口),修改其值,再写回原位置。[1][2]

必须要先读操作的一个原因是,系统架构往往只允许字(word)级的读写,必须先读出那些不做修改的位元,保持不变再写回。写成C语言语句类似于:

*pRegister |= SOME_BIT;

Read-modify-write指令用于IO端口时,可能会产生出乎意料的结果,如无法给一个比特置位。这往往是因为写操作并不影响到读操作的源寄存器。[3]

RAID也使用这一术语描述原子操作的read-modify-write序列。[4] Such RAID levels include RAID 4, RAID 5 and RAID 6.

参见

  • 可线性化
  • Read-erase-modify-write

参考文献

  1. "Writing Lock-Free Code: A Corrected Queue". Dr. Dobb's Journal. 页面存档备份,存于 by Herb Sutter: "Compare-and-swap (CAS) is ... widely available ... However, some systems instead provide the equivalently powerful load-linked/store-conditional (LL/SC) instead."
  2. Herlihy, Maurice. (PDF). ACM Transactions on Programming Languages and Systems. January 1991, 13 (1): 124–149 [2007-05-20]. doi:10.1145/114005.102808. (原始内容存档 (PDF)于2011-06-05).
  3. . techref.massmind.org. [2017-11-22]. (原始内容存档于2017-12-01).
  4. . umass.edu. [2013-10-04]. (原始内容存档于2013-10-24).
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.