<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
I did. I was. I think it is ok now.<BR>
 <BR>
 - Jay<BR> <BR>
<HR id=stopSpelling>
Subject: Re: [M3devel] deadlock in Win32 threads?<BR>From: hosking@cs.purdue.edu<BR>Date: Thu, 10 Dec 2009 12:32:36 -0500<BR>CC: m3devel@elegosoft.com<BR>To: jay.krell@cornell.edu<BR><BR><BASE>
<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><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'">I thought you were saying you had a problem with access to traced state...</FONT></SPAN></DIV>
<DIV><FONT class=ecxApple-style-span color=#0000ff face="'Gill Sans'"><SPAN style="FONT-SIZE: medium" class=ecxApple-style-span><BR></SPAN></FONT></DIV></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></DIV></SPAN></SPAN></DIV>
<DIV>
<DIV>On 10 Dec 2009, at 11:44, 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; WORD-SPACING: 0px" class=ecxApple-style-span>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxhmmessage>ok.<BR> <BR>LockMutex and BroadcastHeap no longer take the giant lock, for different reasons.<BR>  BroadcastHeap just sets a boolean that is looked at by UnlockHeap.<BR>     Not my doing, but I just moved it from head to release.<BR>  LockMutex I changed to just EnterCriticalSection.<BR>     My doing.<BR><BR> <BR>BroadcastHeap need not take the heap lock either, it's just doing an atomic store, but its caller in this case already has it.<BR> That probably has to be either way. If the caller didn't have it, and was therefore going to be leaving it soon,<BR>  then BroadcastHeap would have to call Broadcast and take the giant lock.<BR> <BR> <BR>I'd just as soon not have the thread code touch any traced data, but Thread.T, Thread.Mutex, Thread.Condition are all traced.<BR><BR> - Jay<BR><BR> <BR>
<HR id=ecxstopSpelling>
From:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</A><BR>Date: Thu, 10 Dec 2009 11:12:45 -0500<BR>To:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</A><BR>CC:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</A><BR>Subject: Re: [M3devel] deadlock in Win32 threads?<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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-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=ecxecxApple-style-span>
<DIV><FONT class=ecxecxApple-style-span color=#0000ff face="'Gill Sans'"><SPAN style="FONT-SIZE: medium" class=ecxecxApple-style-span>I am very uneasy with this -- it is not a solution...  You need to be able to reason about the threads system and how it manipulates traced state.</SPAN></FONT></DIV></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></DIV></SPAN></SPAN></DIV><BR>
<DIV>
<DIV>On 10 Dec 2009, at 02:43, Jay K wrote:</DIV><BR class=ecxecxApple-interchange-newline>
<BLOCKQUOTE><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; WORD-SPACING: 0px" class=ecxecxApple-style-span>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxecxhmmessage>I think it is ok now.<BR>Though there is still some mystery, like why did it work before?<BR>There may also still be a race between the extra writes I put and<BR>the "real" uses of traced data.<BR>Maybe I can reduce the traced data.<BR> <BR> - Jay<BR> <BR>
<HR id=ecxecxstopSpelling>
From:<SPAN class=ecxecxApple-converted-space> </SPAN><A href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</A><BR>To:<SPAN class=ecxecxApple-converted-space> </SPAN><A href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</A><BR>Date: Thu, 10 Dec 2009 06:59:34 +0000<BR>CC:<SPAN class=ecxecxApple-converted-space> </SPAN><A href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</A><BR>Subject: Re: [M3devel] deadlock in Win32 threads?<BR><BR>Hm. First, what changed is probably the movement of stuff from traced to untraced??<BR>Which makes it more efficient and more like pthreads.<BR>I might try putting that back.<BR> <BR> <BR>What I have now though, is that in T, Mutex, and Condition, I put an integer field writeToBlahBlah.<BR>Every time before Lock(giant), whatever, t, m, c, I have I write to that field.<BR>That drastically mitigates this problem and it goes away.<BR> <BR> <BR>However that still leaves me with a similar deadlock.<BR> <BR> <BR>This thread is stuck trying to suspend everyone:<BR> <BR>0:000> ~*k<BR>.  0  Id: a64.1258 Suspend: 1 Teb: 7ffdf000 Unfrozen<BR>ChildEBP RetAddr<BR>0012fd1c 006d033e m3core!RTThread__SuspendOthers+0xdd<BR>0012fd6c 006d02f0 m3core!RTCollector__CollectSomeInStateZero+0x12<BR>0012fd80 006cff87 m3core!RTCollector__CollectSome+0x6e<BR>0012fdc4 006c817c m3core!RTHeapRep__CollectEnough+0x9b<BR>0012fe04 006c7d06 m3core!RTAllocator__AllocTraced+0xd7<BR>0012fe40 006c7348 m3core!RTAllocator__GetOpenArray+0x97<BR>0012fe68 0035dc23 m3core!RTHooks__AllocateOpenArray+0x19<BR><BR> <BR>This thread is stuck trying to get the heap lock.<BR>It is I presume "inCritical" already.<BR> <BR> <BR>   3  Id: a64.1750 Suspend: 2 Teb: 7ffdb000 Unfrozen<BR>ChildEBP RetAddr<BR>01c7fb84 7c90df5a ntdll!KiFastSystemCallRet<BR>01c7fb88 7c91b24b ntdll!ZwWaitForSingleObject+0xc<BR>01c7fc10 7c901046 ntdll!RtlpWaitForCriticalSection+0x132<BR>01c7fc18 006ed42d ntdll!RtlEnterCriticalSection+0x46<BR>01c7fc24 006ec15e m3core!ThreadWin32__Lock+0xd<BR>01c7fc3c 006c8176 m3core!RTOS__LockHeap+0x2c<BR>01c7fc7c 006c7d06 m3core!RTAllocator__AllocTraced+0xd1<BR>01c7fcb8 006c7348 m3core!RTAllocator__GetOpenArray+0x97<BR>01c7fce0 00f8c175 m3core!RTHooks__AllocateOpenArray+0x19<BR>01c7fd44 00f8b36e m3ui!WinTrestle__CopyRoots+0x165<BR><BR> <BR>The first thread has the heap lock, and isn't giving it up:<BR> <BR>01ebffec 00000000 kernel32!BaseThreadStart+0x37<BR>0:000> ?? m3core!ThreadWin32__heapLock<BR>struct _RTL_CRITICAL_SECTION * 0x00f2b3e0<BR>   +0x00c OwningThread     : 0x00001258<BR><BR> <BR>Suspending the second thread does work, but it stays inCritical.<BR>I'm guessing at some of this.<BR> <BR>The giant lock is no longer relevant.<BR> <BR> <BR>I don't see why pthreads doesn't behave the same.<BR> <BR>I'll have to read the code more.<BR> <BR>Hm. inCritical maybe shouldn't be set actually?<BR>I'll dig more.<BR> <BR> <BR> - Jay<BR><BR><BR> <BR>
<HR id=ecxecxecxstopSpelling>
Subject: Re: [M3devel] deadlock in Win32 threads?<BR>From:<SPAN class=ecxecxApple-converted-space> </SPAN><A href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</A><BR>Date: Wed, 9 Dec 2009 11:13:03 -0500<BR>CC:<SPAN class=ecxecxApple-converted-space> </SPAN><A href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</A><BR>To:<SPAN class=ecxecxApple-converted-space> </SPAN><A href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</A><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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-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=ecxecxecxecxApple-style-span>
<DIV><SPAN style="FONT-SIZE: medium" class=ecxecxecxecxApple-style-span><FONT class=ecxecxecxecxApple-style-span color=#0000ff face="'Gill Sans'">Jay, you're the one closest to the Win32 threading code these days.  Hope you can track it down.</FONT></SPAN></DIV></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></DIV></SPAN></SPAN></DIV><BR>
<DIV>
<DIV>On 9 Dec 2009, at 09:16, Jay K wrote:</DIV><BR class=ecxecxecxecxApple-interchange-newline>
<BLOCKQUOTE><SPAN style="TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; LETTER-SPACING: normal; WORD-SPACING: 0px" class=ecxecxecxecxApple-style-span>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxecxecxecxhmmessage>Win32.<BR> <BR>I have a wierd system..but I think the bug is real.<BR>In particular I was testing a small threading change on head.<BR>  How alertable is managed, to remove its write in LockMutex, so I could remove the giant lock there.<BR>  But I just had the alertable changes.<BR><BR> <BR>It was hanging starting Juno.<BR>So I tried to test release.<BR>You can't use head Juno with release m3core...and I didn't rebuild everything. I'll do that.<BR> So I patched up release m3core to be binary compatible. (I'll probably check that in.)<BR> <BR><BR>Juno still hangs.<BR> <BR><BR>Here is what I see:<BR> <BR> <BR>0:006> ~*k     This funny thing is like gdb's "thread apply all bt".<BR>               ~ is thread; * is all; k is stack.<BR> <BR>[edited]<BR><BR> <BR>   6  Id: 790.b0 Suspend: 1 Teb: 7ffd7000 Unfrozen<BR>ChildEBP RetAddr<BR>0234fbe8 7c90df5a ntdll!KiFastSystemCallRet<BR>0234fbec 7c91b24b ntdll!ZwWaitForSingleObject+0xc<BR>0234fc74 7c901046 ntdll!RtlpWaitForCriticalSection+0x132<BR>0234fc7c 006ecb4e ntdll!RtlEnterCriticalSection+0x46<BR>0234fc88 006ebd31 m3core!ThreadWin32__EnterCriticalSection_heap+0xe [c:\dev2\cm3<BR>.release_branch_cm3_5_8\m3-libs\m3core\src\thread\win32\threadwin32c.c @ 30]<BR>0234fc9c 006d4a51 m3core!RTOS__LockHeap+0x12 [..\src\thread\WIN32\ThreadWin32.m3<BR> @ 960]<BR>0234fcd8 006e92b4 m3core!RTHooks__CheckStoreTraced+0x81 [..\src\runtime\common\R<BR>TCollector.m3 @ 2253]<BR>0234fd0c 00faa995 m3core!ThreadWin32__LockMutex+0xe0 [..\src\thread\WIN32\Thread<BR>Win32.m3 @ 111]<BR>0234fd30 00fd1fd1 m3ui!VBT__Mark+0x2a [..\src\vbt\VBT.m3 @ 1247]<BR>...<BR> <BR> <BR>   7  Id: 790.b34 Suspend: 1 Teb: 7ffd6000 Unfrozen<BR>ChildEBP RetAddr<BR>026dfc5c 7c90df5a ntdll!KiFastSystemCallRet<BR>026dfc60 7c91b24b ntdll!ZwWaitForSingleObject+0xc<BR>026dfce8 7c901046 ntdll!RtlpWaitForCriticalSection+0x132<BR>026dfcf0 006ecb2e ntdll!RtlEnterCriticalSection+0x46<BR>026dfcfc 006e9c33 m3core!ThreadWin32__EnterCriticalSection_giant+0xe [c:\dev2\cm<BR>3.release_branch_cm3_5_8\m3-libs\m3core\src\thread\win32\threadwin32c.c @ 29]<BR>026dfd14 006ec0a1 m3core!Thread__Broadcast+0x12 [..\src\thread\WIN32\ThreadWin32<BR>.m3 @ 276]<BR>026dfd30 006d0285 m3core!RTOS__BroadcastHeap+0x55 [..\src\thread\WIN32\ThreadWin<BR>32.m3 @ 995]<BR>026dfd44 006d0039 m3core!RTCollector__CollectorOff+0x94 [..\src\runtime\common\R<BR>TCollector.m3 @ 716]<BR>026dfd64 006cfff4 m3core!RTCollector_M3_LINE_663+0x40 [..\src\runtime\common\RTC<BR>ollector.m3 @ 666]<BR>026dfda8 006c817c m3core!RTHeapRep__CollectEnough+0x100 [..\src\runtime\common\R<BR>TCollector.m3 @ 671]<BR>026dfde8 006c7793 m3core!RTAllocator__AllocTraced+0xd7 [..\src\runtime\common\RT<BR>Allocator.m3 @ 364]<BR>026dfe1c 006c728d m3core!RTAllocator__GetTracedObj+0x8c [..\src\runtime\common\R<BR>TAllocator.m3 @ 222]<BR>026dfe40 10013797 m3core!RTHooks__AllocateTracedObj+0x15 [..\src\runtime\common\<BR>RTAllocator.m3 @ 120]<BR>026dfe7c 1000fde5 juno_compiler!JunoCompileRep__Cmd+0xcf [..\src\JunoCompile.m3<BR>@ 987]<BR>...<BR> <BR><BR>Let's look at two of our important locks:<BR>?? is the C++ expression evaluator -- the "good" expression evaluator.<BR> <BR><BR>0:006> ?? m3core!ThreadWin32__giant<BR>struct _RTL_CRITICAL_SECTION<BR>   +0x000 DebugInfo        : 0x00156b68 _RTL_CRITICAL_SECTION_DEBUG<BR>   +0x004 LockCount        : 2<BR>   +0x008 RecursionCount   : 1<BR>   +0x00c OwningThread     : 0x000000b0<BR>   +0x010 LockSemaphore    : 0x00000708<BR>   +0x014 SpinCount        : 0<BR> <BR> <BR>0:006> ?? m3core!ThreadWin32__heap<BR>struct _RTL_CRITICAL_SECTION<BR>   +0x000 DebugInfo        : 0x00156ba0 _RTL_CRITICAL_SECTION_DEBUG<BR>   +0x004 LockCount        : 1<BR>   +0x008 RecursionCount   : 1<BR>   +0x00c OwningThread     : 0x00000b34<BR>   +0x010 LockSemaphore    : 0x000006ec<BR>   +0x014 SpinCount        : 0<BR> <BR> <BR>So you can see there is a circularity and deadlock.<BR>Thread 6 owns giant lock and is waiting for heap lock.<BR>Thread 7 owns heap lock and is waiting for giant lock.<BR> <BR><BR>This occurs because Win32 LockMutex uses traced references within the giant lock. ?<BR>Use of traced references implies a possible need to take the heap lock.<BR>Doing darn near anything implies a need to use the giant lock.<BR> <BR><BR>Any ideas Tony?<BR> <BR><BR>I'm not crazy or have a messed up tree, right?<BR>I mean, now that I've discussed it, the deadlock potential is obviously there, right?<BR> <BR><BR>Pthreads is safe of course, no giant lock.<BR> <BR><BR>I was about to remove the giant lock from LockMutex/UnlockMutex.<BR>That should help?<BR>The giant lock would still remain though.<BR> <BR><BR>Now, we know that condition variables are implementable well enough on Win32.<BR>Either with a giant lock, or how Java does it.<BR> Aside: I don't fully understand the Java implementation, but if it works, it is goodness.<BR> It has no giant lock. I don't understand how the sequence numbers make it work.<BR> <BR><BR>However the Modula-3 giant lock implementation..I am trusting Birrel here<BR>that it works at ll..doesn't interact well with traced references within its own implementation?<BR>Maybe this stuff can be teased apart?<BR> <BR> <BR>Same thing with a coherent (I think) release build:<BR> <BR>0:008> ~*k<BR> <BR>   0  Id: f58.d0 Suspend: 1 Teb: 7ffdf000 Unfrozen<BR>ChildEBP RetAddr<BR>0012f5f4 7c90df5a ntdll!KiFastSystemCallRet<BR>0012f5f8 7c91b24b ntdll!ZwWaitForSingleObject+0xc<BR>0012f680 7c901046 ntdll!RtlpWaitForCriticalSection+0x132<BR>0012f688 005ece7e ntdll!RtlEnterCriticalSection+0x46<BR>0012f694 005ec06d m3core!ThreadWin32__EnterCriticalSection_heap+0xe<BR>0012f6a8 005d4ab1 m3core!RTOS__LockHeap+0x12<BR>0012f6e4 005e9434 m3core!RTHooks__CheckStoreTraced+0x81<BR>0012f718 00facedc m3core!ThreadWin32__LockMutex+0xe0<BR>0012f774 00fb0b51 m3ui!VBTClass__Rescreen+0xed<BR><BR>...<BR> <BR>   7  Id: f58.80 Suspend: 1 Teb: 7ffd9000 Unfrozen<BR>ChildEBP RetAddr<BR>0240fc98 7c90df5a ntdll!KiFastSystemCallRet<BR>0240fc9c 7c91b24b ntdll!ZwWaitForSingleObject+0xc<BR>0240fd24 7c901046 ntdll!RtlpWaitForCriticalSection+0x132<BR>0240fd2c 005ece5e ntdll!RtlEnterCriticalSection+0x46<BR>0240fd38 005e9e6c m3core!ThreadWin32__EnterCriticalSection_giant+0xe<BR>0240fd50 005ec3dd m3core!Thread__Broadcast+0x12<BR>0240fd6c 005d02e5 m3core!RTOS__BroadcastHeap+0x55<BR>0240fd80 005d0099 m3core!RTCollector__CollectorOff+0x94<BR><BR> <BR>0:008> ?? m3core!ThreadWin32__giant<BR>struct _RTL_CRITICAL_SECTION<BR>   +0x000 DebugInfo        : 0x7c97e9c0 _RTL_CRITICAL_SECTION_DEBUG<BR>   +0x004 LockCount        : 5<BR>   +0x008 RecursionCount   : 1<BR>   +0x00c OwningThread     : 0x000000d0<BR>   +0x010 LockSemaphore    : 0x00000700<BR>   +0x014 SpinCount        : 0<BR><BR> <BR>0:008> ?? m3core!ThreadWin32__heap<BR>struct _RTL_CRITICAL_SECTION<BR>   +0x000 DebugInfo        : 0x7c97e9e0 _RTL_CRITICAL_SECTION_DEBUG<BR>   +0x004 LockCount        : 1<BR>   +0x008 RecursionCount   : 1<BR>   +0x00c OwningThread     : 0x00000080<BR>   +0x010 LockSemaphore    : 0x000006fc<BR>   +0x014 SpinCount        : 0<BR> <BR> <BR>80 has the heap lock and is trying to get the giant lock<BR>D0 has the giant lock and is trying to get the heap lock<BR>  Because of the use of traced references in LockMutex.<BR> <BR><BR> - Jay<BR><BR></DIV></SPAN></BLOCKQUOTE></DIV><BR></DIV></SPAN><BR class=ecxecxApple-interchange-newline></BLOCKQUOTE></DIV><BR></DIV></SPAN><BR class=ecxApple-interchange-newline></BLOCKQUOTE></DIV><BR>                                         </body>
</html>