Skip to content

Latest commit

 

History

History
94 lines (75 loc) · 2.78 KB

nf-winnt-memorybarrier.md

File metadata and controls

94 lines (75 loc) · 2.78 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:winnt.MemoryBarrier
MemoryBarrier function (winnt.h)
Creates a hardware memory barrier (fence) that prevents the CPU from re-ordering read and write operations. It may also prevent the compiler from re-ordering read and write operations.
MemoryBarrier
MemoryBarrier function
base.memorybarrier
winnt/MemoryBarrier
base\memorybarrier.htm
backup
f2c06679-fa2f-4357-ae11-6cec1e50fd8f
12/05/2018
MemoryBarrier, MemoryBarrier function, base.memorybarrier, winnt/MemoryBarrier
winnt.h
Windows.h
Windows
Windows Vista [desktop apps \| UWP apps]
Windows Server 2003 [desktop apps \| UWP apps]
Windows
19H1
MemoryBarrier
winnt/MemoryBarrier
c++
APIRef
kbSyntax
HeaderDef
Winnt.h
MemoryBarrier

MemoryBarrier function

-description

Creates a hardware memory barrier (fence) that prevents the CPU from re-ordering read and write operations. It may also prevent the compiler from re-ordering read and write operations.

-remarks

Use this macro or the interlocked functions when the order of memory read and write operations is critical for program operation.

The _ReadBarrier, _WriteBarrier, and _ReadWriteBarrier compiler intrinsics prevent compiler re-ordering only. With Visual Studio 2003, volatile to volatile references are ordered; the compiler will not re-order volatile variable access. With Visual Studio 2005, the compiler also uses acquire semantics for read operations on volatile variables and release semantics for write operations on volatile variables (when supported by the CPU). For more information, see Synchronization and Multiprocessor Issues.

This macro can be called on all processor platforms where Windows is supported, but it has no effect on some platforms. The definition varies from platform to platform. The following are some definitions of this macro in Winnt.h.

#ifdef _AMD64_
#define MemoryBarrier __faststorefence
#endif

#ifdef _IA64_
#define MemoryBarrier __mf
#endif

// x86

FORCEINLINE
VOID
MemoryBarrier (
    VOID
    )
{
    LONG Barrier;
    __asm {
        xchg Barrier, eax
    }
}

-see-also

Interlocked Variable Access