<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
<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>Maybe some of them need not be?<BR>I have a simple implementation but it fails.<BR><BR></SPAN>
<DIV><BR></DIV>
<DIV>?</DIV>
 <BR>
Attached. Tried to put this in for Thread.Mutex, not the static locks. It is based on the Java code.<BR>
<DIV>NewLockE, LockE, UnlockE.</DIV>
<DIV> </DIV>
<DIV>typedef struct _LockE_t { /* E = exclusive */<BR>    long count;<BR>    int owner;<BR>    HANDLE event;<BR>} LockE_t;</DIV>
<DIV> </DIV>
<DIV>void __cdecl ThreadWin32__DeleteLockE(LockE_t* lock)<BR>/* E = exclusive */<BR>{<BR>    if (lock)<BR>    {<BR>        HANDLE event = lock->event;<BR>        assert(lock->owner == 0);<BR>        assert(lock->count == -1);<BR>        if (event)<BR>            CloseHandle(event);<BR>        HeapFree(GetProcessHeap(), 0, lock);<BR>    }<BR>}</DIV>
<DIV> </DIV>
<DIV>LockE_t* __cdecl ThreadWin32__NewLockE(void)<BR>/* E = exclusive */<BR>{<BR>    HANDLE event;<BR>    LockE_t* lock = (LockE_t*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lock));<BR>    if (!lock)<BR>        goto Error;<BR>    lock->owner = 0;<BR>    lock->count = -1;<BR>    if (!(lock->event = CreateEventA(0, 0, 0, 0)))<BR>        goto Error;<BR>    return lock;<BR>Error:<BR>    ThreadWin32__DeleteLockE(lock);<BR>    return NULL;<BR>}</DIV>
<DIV> </DIV>
<DIV>void __cdecl ThreadWin32__LockE(LockE_t* lock)<BR>/* E = exclusive */<BR>{<BR>    if (InterlockedIncrement(&lock->count) != 0)<BR>        WaitForSingleObject(lock->event, INFINITE);<BR>    assert(lock->owner == 0);<BR>    lock->owner = GetCurrentThreadId();<BR>}</DIV>
<DIV> </DIV>
<DIV>void __cdecl ThreadWin32__UnlockE(LockE_t* lock)<BR>/* E = exclusive */<BR>{<BR>    assert(lock->owner == GetCurrentThreadId());<BR>    lock->owner = 0;<BR>    if (InterlockedDecrement(&lock->count) >= 0)<BR>        SetEvent(lock->event);<BR>}<BR></DIV>
<DIV><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> <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:16:08 -0500<BR>To:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:jkrell@elego.de">jkrell@elego.de</A><BR>CC:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</A><BR>Subject: Re: [M3commit] CVS Update: cm3<BR><BR>Umm.  Modula-3 locks are *not* recursive...</DIV>
<BLOCKQUOTE>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxhmmessage>
<DIV><BR></DIV>
<DIV>
<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><FONT class=ecxecxApple-style-span face="Gill Sans"><SPAN style="FONT-FAMILY: 'Gill Sans'; COLOR: rgb(0,0,255)" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: 'Gill Sans'; COLOR: rgb(0,0,255)" class=ecxecxApple-style-span>Antony Hosking</SPAN></SPAN></FONT></FONT><FONT class=ecxecxApple-style-span face="Gill Sans"><SPAN style="FONT-FAMILY: 'Gill Sans'" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: 'Gill Sans'" class=ecxecxApple-style-span><SPAN class=ecxecxApple-converted-space> </SPAN>|<SPAN class=ecxecxApple-converted-space> </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 'Gill Sans'" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: 'Gill Sans'" class=ecxecxApple-style-span>Associate Professor</SPAN></SPAN><SPAN style="FONT-FAMILY: 'Gill Sans'" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: 'Gill Sans'" class=ecxecxApple-style-span> | Computer Science | Purdue University</SPAN></SPAN></FONT></DIV>
<DIV><FONT class=ecxecxApple-style-span face=GillSans-Light><SPAN style="FONT-FAMILY: GillSans-Light" class=ecxecxApple-style-span>305 N. University Street | West Lafayette | IN 47907 | USA</SPAN></FONT></DIV>
<DIV><FONT class=ecxecxApple-style-span color=#0000ff face="Gill Sans"><SPAN style="FONT-FAMILY: 'Gill Sans'; COLOR: rgb(0,0,255)" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: 'Gill Sans'; COLOR: rgb(0,0,255)" class=ecxecxApple-style-span>Office</SPAN></SPAN></FONT><FONT class=ecxecxApple-style-span face=GillSans-Light><SPAN style="FONT-FAMILY: GillSans-Light" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: GillSans-Light" class=ecxecxApple-style-span>  <?XML:NAMESPACE PREFIX = SKYPE /><SKYPE:SPAN id=softomate_v3_highlight_0 class=skype_v3_tb_injection title=Call this phone number in United States of America with Skype: +17654946001 rtl="1" skypeid="0" skypeaction="call" nof="" isfax="" freecall="" fwidth=".w16" type=".flex" mode=".compat" path="file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/" durex2="%DADDYHEIGHT%" durex="%DADDYWIDTH%" context="+1 765 494 6001"><SKYPE:SPAN id=skype_v3_tb_img_r0 class=skype_v3_tb_imgR></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_text0 class=skype_v3_tb_injectionIn><SKYPE:SPAN id=skype_v3_tb_innerText0 class=skype_v3_tb_innerText> +1 765 494 6001 </SKYPE:SPAN></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_img_s0 class=skype_v3_tb_imgS></SKYPE:SPAN><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/inactive_a.compat.flex.w16.gif)" id=skype_v3_tb_droppart_0 class=skype_v3_tb_imgA title="Skype actions" skypeid="0" skypeaction="drop" skypesms="0"><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/famfamfam/US.gif)" id=skype_v3_tb_img_f0 class=skype_v3_tb_imgFlag></SKYPE:SPAN></SKYPE:SPAN></SKYPE:SPAN> <SKYPE:SPAN id=softomate_v3_print_0 class=skype_v3_tb_injection_print context="">+1 765 494 6001</SKYPE:SPAN>  <SPAN class=ecxApple-converted-space> </SPAN><SKYPE:SPAN id=softomate_v3_highlight_1 class=skype_v3_tb_injection title=Call this phone number in United States of America with Skype: +17654946001 skypeid="1" skypeaction="call" nof="" isfax="" freecall="" fwidth=".w16" type=".flex" mode=".compat" path="file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/" durex2="%DADDYHEIGHT%" durex="%DADDYWIDTH%" context="+1 765 494 6001"><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/inactive_a.compat.flex.w16.gif)" id=skype_v3_tb_droppart_1 class=skype_v3_tb_imgA title="Skype actions" skypeid="1" skypeaction="drop" skypesms="0"><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/famfamfam/US.gif)" id=skype_v3_tb_img_f1 class=skype_v3_tb_imgFlag></SKYPE:SPAN></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_img_s1 class=skype_v3_tb_imgS></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_text1 class=skype_v3_tb_injectionIn><SKYPE:SPAN id=skype_v3_tb_innerText1 class=skype_v3_tb_innerText> +1 765 494 6001 </SKYPE:SPAN></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_img_r1 class=skype_v3_tb_imgR></SKYPE:SPAN></SKYPE:SPAN> <SKYPE:SPAN id=softomate_v3_print_1 class=skype_v3_tb_injection_print context="">+1 765 494 6001</SKYPE:SPAN> <SPAN class=ecxApple-converted-space> </SPAN>|<SPAN class=ecxecxApple-converted-space> </SPAN></SPAN></SPAN></FONT><FONT class=ecxecxApple-style-span color=#0000ff face="Gill Sans"><SPAN style="FONT-FAMILY: 'Gill Sans'; COLOR: rgb(0,0,255)" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: 'Gill Sans'; COLOR: rgb(0,0,255)" class=ecxecxApple-style-span>Mobile</SPAN></SPAN></FONT><FONT class=ecxecxApple-style-span face=GillSans-Light><SPAN style="FONT-FAMILY: GillSans-Light" class=ecxecxApple-style-span><SPAN style="FONT-FAMILY: GillSans-Light" class=ecxecxApple-style-span><SPAN class=ecxecxApple-converted-space> </SPAN> <SKYPE:SPAN id=softomate_v3_highlight_2 class=skype_v3_tb_injection title=Call this phone number in United States of America with Skype: +17654275484 skypeid="2" skypeaction="call" nof="" isfax="" freecall="" fwidth=".w16" type=".flex" mode=".compat" path="file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/" durex2="%DADDYHEIGHT%" durex="%DADDYWIDTH%" context="+1 765 427 5484"><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/inactive_a.compat.flex.w16.gif)" id=skype_v3_tb_droppart_2 class=skype_v3_tb_imgA title="Skype actions" skypeid="2" skypeaction="drop" skypesms="1"><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/famfamfam/US.gif)" id=skype_v3_tb_img_f2 class=skype_v3_tb_imgFlag></SKYPE:SPAN></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_img_s2 class=skype_v3_tb_imgS></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_text2 class=skype_v3_tb_injectionIn><SKYPE:SPAN id=skype_v3_tb_innerText2 class=skype_v3_tb_innerText> +1 765 427 5484 </SKYPE:SPAN></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_img_r2 class=skype_v3_tb_imgR></SKYPE:SPAN></SKYPE:SPAN> <SKYPE:SPAN id=softomate_v3_print_2 class=skype_v3_tb_injection_print context="">+1 765 427 5484</SKYPE:SPAN>  <SPAN class=ecxApple-converted-space> </SPAN><SKYPE:SPAN id=softomate_v3_highlight_3 class=skype_v3_tb_injection title=Call this phone number in United States of America with Skype: +17654275484 skypeid="3" skypeaction="call" nof="" isfax="" freecall="" fwidth=".w16" type=".flex" mode=".compat" path="file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/" durex2="%DADDYHEIGHT%" durex="%DADDYWIDTH%" context="+1 765 427 5484"><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/inactive_a.compat.flex.w16.gif)" id=skype_v3_tb_droppart_3 class=skype_v3_tb_imgA title="Skype actions" skypeid="3" skypeaction="drop" skypesms="1"><SKYPE:SPAN style="BACKGROUND-IMAGE: url(file://C:/Users/jay/Temp/__SkypeIEToolbar_Cache/e70d95847a8f5723cfca6b3fd9946506/static/famfamfam/US.gif)" id=skype_v3_tb_img_f3 class=skype_v3_tb_imgFlag></SKYPE:SPAN></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_img_s3 class=skype_v3_tb_imgS></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_text3 class=skype_v3_tb_injectionIn><SKYPE:SPAN id=skype_v3_tb_innerText3 class=skype_v3_tb_innerText> +1 765 427 5484 </SKYPE:SPAN></SKYPE:SPAN><SKYPE:SPAN id=skype_v3_tb_img_r3 class=skype_v3_tb_imgR></SKYPE:SPAN></SKYPE:SPAN> <SKYPE:SPAN id=softomate_v3_print_3 class=skype_v3_tb_injection_print context="">+1 765 427 5484</SKYPE:SPAN> </SPAN></SPAN></FONT></DIV>
<DIV><FONT class=ecxecxApple-style-span face=GillSans-Light><BR class=ecxecxkhtml-block-placeholder></FONT></DIV></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN><BR class=ecxecxApple-interchange-newline></SPAN></DIV></SPAN></SPAN><BR class=ecxecxApple-interchange-newline></DIV><BR>
<DIV>
<DIV>On 10 Dec 2009, at 16:08, Jay Krell wrote:</DIV><BR class=ecxecxApple-interchange-newline>
<BLOCKQUOTE>
<DIV>CVSROOT:<SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span> </SPAN>/usr/cvs<BR>Changes by:<SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span> </SPAN>jkrell@birch.<SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span> </SPAN>09/12/10 16:08:58<BR><BR>Modified files:<BR><SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span></SPAN>cm3/m3-libs/m3core/src/thread/WIN32/: ThreadWin32.i3<SPAN class=ecxApple-converted-space> </SPAN><BR><SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span></SPAN>                                     ThreadWin32.m3<SPAN class=ecxApple-converted-space> </SPAN><BR><SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span></SPAN>                                     ThreadWin32C.c<SPAN class=ecxApple-converted-space> </SPAN><BR><BR>Log message:<BR><SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span></SPAN>rename Lock => LockRE for recursive/exclusive<BR><SPAN style="WHITE-SPACE: pre" class=ecxecxApple-tab-span></SPAN>so that we might introduce LockE for exclusive<BR></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV></SPAN><BR class=ecxApple-interchange-newline></BLOCKQUOTE><BR>                                          </body>
</html>