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.

参见[编辑]

参考文献[编辑]

  1. ^ "Writing Lock-Free Code: A Corrected Queue" 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. Wait-free synchronization (PDF). ACM Trans. Program. Lang. Syst. January 1991, 13 (1): 124–149 [2007-05-20]. doi:10.1145/114005.102808. 
  3. ^ Massmind: "The read–modify–write problem"
  4. ^ Basic RAID Organizations. umass.edu. [2013-10-04].