Note
When working at the hardware level, Peterson's algorithm is typically not needed to achieve atomic access. Some processors have special instructions, like test-and-set or compare-and-swap, that, by locking the memory bus, can be used to provide mutual exclusion in SMP systems.
Most modern CPUs reorder memory accesses to improve execution efficiency (see memory ordering for types of reordering allowed). Such processors invariably give some way to force ordering in a stream of memory accesses, typically through a memory barrier instruction. Implementation of Peterson's and related algorithms on processors which reorder memory accesses generally requires use of such operations to work correctly to keep sequential operations from happening in an incorrect order. Note that reordering of memory accesses can happen even on processors that don't reorder instructions (such as the PowerPC processor in the Xbox 360).
Most such CPUs also have some sort of guaranteed atomic operation, such as XCHG on x86 processors and Load-Link/Store-Conditional on Alpha, MIPS, PowerPC, and other architectures. These instructions are intended to provide a way to build synchronization primitives more efficiently than can be done with pure shared memory approaches.
Read more about this topic: Peterson's Algorithm
Famous quotes containing the word note:
“A note as from a single place,
A slender tinkling fall that made
Now drops that floated on the pool
Like pearls, and now a silver blade.”
—Robert Frost (18741963)
“Is whispering nothing?
Is leaning cheek to cheek? Is meeting noses?
Kissing with inside lip? Stopping the career
Of laughter with a sigh?a note infallible
Of breaking honesty.”
—William Shakespeare (15641616)
“In it he proves that all things are true and states how the truths of all contradictions may be reconciled physically, such as for example that white is black and black is white; that one can be and not be at the same time; that there can be hills without valleys; that nothingness is something and that everything, which is, is not. But take note that he proves all these unheard-of paradoxes without any fallacious or sophistical reasoning.”
—Savinien Cyrano De Bergerac (16191655)