On 7/9/07, Peter Ritchie
<[EMAIL PROTECTED]> wrote:
The Monitor.Exit generated by the lock statement has an implicit memory
barrier that will flush the CPU write cache at the end of the lock block.

You were right and I was wrong - somewhere (AwareLock::LeaveHelper
used by the SyncBlock implementation) in the implementation of Exit
(in SSCLI 2) there's a CAS loop which looks like this:

if (FastInterlockCompareExchangeRelease((LONG*)&m_MonitorHeld, state -
1, state) == state)...

I haven't checked what FastInterlockCompareExchangeRelease maps to,
but surely to InterlockedCompareExchangeRelease which on x86 is a full
barrier and on IA64 has release semantics, ensuring that all
processors see everything written before Exit returns, so the extra
memory barrier is in fact not needed.

Cheers,
Stoyan

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to