Interlocked.MemoryBarrier Interlocked.MemoryBarrier Interlocked.MemoryBarrier Interlocked.MemoryBarrier Method

定義

同步記憶體存取,如下所示:執行目前執行緒的處理器無法用這種方式重新排列指令:呼叫 MemoryBarrier() 前的記憶體存取在呼叫 MemoryBarrier() 後的記憶體存取之後執行。Synchronizes memory access as follows: The processor that executes the current thread cannot reorder instructions in such a way that memory accesses before the call to MemoryBarrier() execute after memory accesses that follow the call to MemoryBarrier().

public:
 static void MemoryBarrier();
public static void MemoryBarrier ();
static member MemoryBarrier : unit -> unit
Public Shared Sub MemoryBarrier ()

備註

為了方便起見,這個方法Interlocked已加入至.NET Framework 4.5.NET Framework 4.5中的類別,它是Thread.MemoryBarrier方法的包裝函式。This method was added to the Interlocked class in the .NET Framework 4.5.NET Framework 4.5 as a convenience; it's a wrapper for the Thread.MemoryBarrier method.

MemoryBarrier只有在具有弱式記憶體排序(例如,採用多個 Intel Itanium 處理器的系統)的多處理器系統上才需要。MemoryBarrier is required only on multiprocessor systems that have weak memory ordering (for example, a system that employs multiple Intel Itanium processors).

C# 在lock大部分的情況下,語句、Visual Basic SyncLock語句或Monitor類別會提供更簡單的方式來同步處理資料。For most purposes, the C# lock statement, the Visual Basic SyncLock statement, or the Monitor class provide easier ways to synchronize data.

適用於