Memory Barrier - Multithreaded Programming and Memory Visibility

Multithreaded Programming and Memory Visibility

See also: Memory model (programming)

Multithreaded programs usually use synchronization primitives provided by a high-level programming environment, such as Java and .NET Framework, or an application programming interface (API) such as POSIX Threads or Windows API. Primitives such as mutexes and semaphores are provided to synchronize access to resources from parallel threads of execution. These primitives are usually implemented with the memory barriers required to provide the expected memory visibility semantics. In such environments explicit use of memory barriers is not generally necessary.

Each API or programming environment in principle has its own high-level memory model that defines its memory visibility semantics. Although programmers do not usually need to use memory barriers in such high level environments, it is important to understand their memory visibility semantics, to the extent possible. Such understanding is not necessarily easy to achieve because memory visibility semantics are not always consistently specified or documented.

Just as programming language semantics are defined at a different level of abstraction than machine language opcodes, a programming environment's memory model is defined at a different level of abstraction than that of a hardware memory model. It is important to understand this distinction and realize that there is not always a simple mapping between low-level hardware memory barrier semantics and the high-level memory visibility semantics of a particular programming environment. As a result, a particular platform's implementation of (say) POSIX Threads may employ stronger barriers than required by the specification. Programs which take advantage of memory visibility as-implemented rather than as-specified may not be portable.

Read more about this topic:  Memory Barrier

Famous quotes containing the words programming, memory and/or visibility:

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)

    It must be a peace without victory.... Victory would mean peace forced upon the losers, a victor’s terms imposed upon the vanquished. It would be accepted in humiliation, under duress, at an intolerable sacrifice, and would leave a sting, a resentment, a bitter memory upon which the terms of peace would rest, not permanently, but only as upon quicksand.
    Woodrow Wilson (1856–1924)

    My children have taught me things. Things I thought I knew. The most profound wisdom they have given me is a respect for human vulnerability. I have known that people are resilient, but I didn’t appreciate how fragile they are. Until children learn to hide their feelings, you read them in their faces, gestures, and postures. The sheer visibility of shyness, pain, and rejection let me recognize and remember them.
    Shirley Nelson Garner (20th century)