<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
I don't know. I just look at all code overly critically..including for overly coarse grained locking (which includes some vs. none).<BR>
I guess the argument could be that the critical section -- the part of code that executes under the lock -- is very short, so it can't make much of a difference.<BR>
<BR>
Writing the global with an "InterlockedExchange" might be good.<BR>
<BR>
Maybe we should add this as a portably available interface?<BR>
"This" being MemoryBarrier and/or well, er, um, I guess you already did, the IA64 stuff, which is similar to the Win32 stuff.<BR>
I should update the NT/x86 backend for that stuff and then we can move on and use them.<BR>
<BR>
- Jay<BR><BR> <BR>
<HR id=stopSpelling>
From: hosking@cs.purdue.edu<BR>To: jay.krell@cornell.edu<BR>Date: Sun, 8 Nov 2009 19:39:00 -0500<BR>CC: m3devel@elegosoft.com<BR>Subject: Re: [M3devel] Self() locking slots almost unnecessary -- if only we had "MemoryBarrier".<BR><BR>
<DIV><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="WORD-WRAP: break-word"><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="WORD-WRAP: break-word"><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV><SPAN style="FONT-SIZE: medium" class=ecxApple-style-span><FONT class=ecxApple-style-span color=#0000ff face="'Gill Sans'">Not portably. Different memory models will behave differently. For safety we need the lock. But, seriously, how much contention will there be?</FONT></SPAN></DIV></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></DIV></SPAN></DIV></SPAN></DIV><BR>
<DIV>
<DIV>On 8 Nov 2009, at 19:35, Jay K wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxhmmessage>Self() doesn't have to lock slots AS LONG AS in AssignSlot:<BR> <BR> SUBARRAY (new_slots^, 0, n) := slots^;<BR> slots := new_slots;<BR><BR>occurs in the order written.<BR>That SUBARRAY() := finishes before slots := runs.<BR>Aggressively compilers/processors need not execute these in the order written.<BR> <BR>Do we have a way to guarantee that?<BR> <BR>Something like:<BR> SUBARRAY (new_slots^, 0, n) := slots^;<BR>> MemoryBarrier();<BR> slots := new_slots;<BR><BR>?<BR> <BR>MemoryBarrier on Windows is implemented as one "special" instruction -- for x86, AMD64, and IA64.<BR>Those implementations are portable to any OS running those architectures.<BR>Though they aren't expressed in a portable form (x86 inline assembly and C compiler intrinsincs).<BR>In particular:<BR> <BR>winnt.h:<BR>amd64:<BR>#define MemoryBarrier __faststorefence<BR><BR>x86:<BR>FORCEINLINE<BR>VOID<BR>MemoryBarrier (<BR> VOID<BR> )<BR>{<BR> LONG Barrier;<BR> __asm {<BR> xchg Barrier, eax<BR> }<BR>}<BR><BR>ia64:<BR>#define MemoryBarrier __mf<BR><BR> <BR> - Jay<BR> <BR></DIV></SPAN></BLOCKQUOTE></DIV><BR> </body>
</html>