Re: Memory barrier note
From: Scott Allen (bitmask_at_[nospam)
Date: 06/10/04
- Next message: Vijaye Raji: "Re: MenuItem needs a Custom Shortcut"
- Previous message: Jon Skeet [C# MVP]: "Re: do you have to always instantiate variables in C#?"
- In reply to: William Stacey [MVP]: "Re: Memory barrier note"
- Next in thread: William Stacey [MVP]: "Re: Memory barrier note"
- Reply: William Stacey [MVP]: "Re: Memory barrier note"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 10 Jun 2004 12:16:37 -0400
Hi William:
As Jon points out, it really is all about ordering. The lock can only
ensure a consistent view of the memory if everyone follows the
protocol: acquire lock, work with shared memory, release lock.
The problem with double check locking is that only one thread will
ever follow the protocol, everyone else cheats and tries to look at
shared memory without acquiring the same lock. Because of this we have
to strictly control the ordering of the memory operations inside of
the lock. Other threads will be peaking at our work while we still
have a work in progress.
We can use a memory barrier to force a strong order - all memory
writes will be seen by an external observer to happen in the same
order as we programmed them. That's really what it's all about.
-- Scott On Wed, 9 Jun 2004 20:18:27 -0400, "William Stacey [MVP]" <staceywREMOVE@mvps.org> wrote: >Not sure all this ordering stuff is the key (however is also important.) >The memory barrier (AFAICT), flushes the cache on all processors. This >makes sure that when you set a var on one processor, another processor will >read that same memory location and not a cached version of that location >that could be pointing to something else or null. The lock insures the >ordering and sync, the barrier insures the cache does not become an issue. >Please correct if in error. Cheers!
- Next message: Vijaye Raji: "Re: MenuItem needs a Custom Shortcut"
- Previous message: Jon Skeet [C# MVP]: "Re: do you have to always instantiate variables in C#?"
- In reply to: William Stacey [MVP]: "Re: Memory barrier note"
- Next in thread: William Stacey [MVP]: "Re: Memory barrier note"
- Reply: William Stacey [MVP]: "Re: Memory barrier note"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|