Incomputer science,read–modify–write is a class ofatomic operations (such astest-and-set,fetch-and-add, andcompare-and-swap) that both read amemory location and write a new value into it simultaneously, either with a completely new value or some function of the previous value. These operations preventrace conditions in multi-threaded applications. Typically they are used to implementmutexes orsemaphores. These atomic operations are also heavily used innon-blocking synchronization.
Read–modify–write instructions often produce unexpected results when used onI/O devices, as a write operation may not affect the same internalregister that would be accessed in a read operation.[1] This term is also associated withRAID levels that perform actual write operations asatomic read–modify–write sequences.[2] Such RAID levels includeRAID 4,RAID 5 andRAID 6.
To solve the consensus problem in a shared-memory system, concurrent objects must be introduced. A concurrent object, or shared object, is a data structure which helps concurrent processes communicate to reach an agreement. Traditional implementations usingcritical sections face the risk of crashing if some process dies inside the critical section or sleeps for an intolerably long time. Researchers definedwait-freedom as the guarantee that the algorithm completes in a finite number of steps.
The consensus number of a concurrent object is defined to be the maximum number of processes in the system which can reach consensus by the given object in a wait-free implementation.[3] Objects with a consensus number of can implement any object with a consensus number of or lower, but cannot implement any objects with a higher consensus number. The consensus numbers form what is calledHerlihy's hierarchy of synchronization objects.[4]
Consensus number | Objects |
---|---|
atomicread/write registers,mutex | |
test-and-set,swap,fetch-and-add, wait-freequeue orstack | |
... | ... |
n-register assignment | |
... | ... |
compare-and-swap,load-link/store-conditional,[5] memory-to-memory move and swap, queue with peek operation, fetch&cons, sticky byte |
![]() | Thiscomputer science article is astub. You can help Wikipedia byexpanding it. |