<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
To me..with a Win32 background..join means "wait for thread to finish".<BR>
And there is a separate action "get thread result".<BR>
You could consider these one merged operation "wait for thread to finish and get its result".<BR>
In either case, it is reasonable to allow it multiple times.<BR>
Waiting for a thread to finish that has already finished is just fast.<BR>
Getting a thread result that you already got is also easy albeit usually unnecessary.<BR>
 <BR>
Now, if the operation is "wait for thread to finish, get its result, and lose track of its result",<BR>
that isn't idempotent.<BR>
 <BR>
I'm torn. The existing implementations all either support multiple join or have to go out of<BR>
their way to prevent it. Yet Thread.i3 has been commented so presumably forever.<BR>
 <BR>
 - Jay<BR><BR> <BR>
<HR id=stopSpelling>
Date: Tue, 3 Nov 2009 09:36:23 -0500<BR>From: rcoleburn@scires.com<BR>To: m3devel@elegosoft.com<BR>Subject: Re: [M3devel] join twice?<BR><BR>
<DIV>I think the comment in the code is correct.</DIV>
<DIV> </DIV>
<DIV>Semantically, it doesn't make sense to join a thread more than once.  Join is the compliment to Fork.  With fork, one thread becomes two.  With Join, two threads become one.  After they've become one, the 2nd thread is no more, so you can't join to it anymore.</DIV>
<DIV> </DIV>
<DIV>IMO, the implementation should enforce this behavior.  What would be the "benefit" of allowing more than one join?  What does it "mean" to join a "dead thread"?</DIV>
<DIV> </DIV>
<DIV>Regards,</DIV>
<DIV>Randy Coleburn<BR><BR>>>> Tony Hosking <hosking@cs.purdue.edu> 11/2/2009 11:54 PM >>><BR></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=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><FONT class=ecxApple-style-span color=#0000ff face="'Gill Sans'"><SPAN style="FONT-SIZE: medium" class=ecxApple-style-span>OK, sure.  Fair enough.</SPAN></FONT></DIV></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></DIV></SPAN></DIV></SPAN></DIV><BR>
<DIV>
<DIV>On 2 Nov 2009, at 16:43, 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> > (Whether the implementation actually prohibits it or not is an implementation decision.) <SPAN class=ecxApple-converted-space> </SPAN><BR><BR>Tony, I'm sympathetic to the smaller version but I think it is wrong.<BR>"It is a checked runtime error to call this more than once for any t"<BR>is a much different/stronger statement than e.g.<BR>"it is implementation defined what happens if you call join more than once for any t".<BR>The printed Reactor 4.1 docs have the same comment as current Thread.i3.<BR> <BR>You know, ideally if I write:<BR>Thread.Join(t);<BR>Thread.Join(t);<BR><BR>and it works today on any system, it will continue to work on all systems.<BR>I think "implementation defined" is something Modula-3 tries to have less of.<BR> <BR>On the other hand, I think if we foresee it to work trivially on all<BR>forseeable implementations, we can change the interface by removing the comment.<BR>Win32 WaitForSingleObject(thread, INFINITE) is allowed multiple times, though<BR>that isn't the current implementation.<BR><BR> - Jay<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>To:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</A><BR>Date: Mon, 2 Nov 2009 12:59:36 -0500<BR>CC:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</A><BR>Subject: Re: [M3devel] join twice?<BR><BR>I don't know that there ever was a mandate that join can only be called once on a given thread.  But, given that pthread_join is undefined when called more than once on the same thread we probably want to retain the comment.  (Whether the implementation actually prohibits it or not is an implementation decision.)  The point is that we should be free to give the error in some later implementation, so as to not to restrict what semantics the implementation must support. 
<DIV><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>
<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>
<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> +1 765 494 6001 |<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>+1 765 427 5484</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></DIV></SPAN><BR class=ecxecxApple-interchange-newline></DIV><BR>
<DIV>
<DIV>On 2 Nov 2009, at 10:11, 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; COLOR: rgb(0,0,0); WORD-SPACING: 0px" class=ecxecxApple-style-span>
<DIV style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt" class=ecxecxhmmessage>Thread.i3:<BR> <BR> <BR>PROCEDURE Join(t: T): REFANY;<BR>(* Wait until "t" has terminated and return its result. It is a<BR>   checked runtime error to call this more than once for any "t". *)<BR><BR> <BR>ThreadWin32.m3:<BR> <BR> <BR>PROCEDURE Join(t: T): REFANY =<BR>  VAR res: REFANY;<BR>  BEGIN<BR>    LOCK t DO<BR>      IF t.joined THEN Die(ThisLine(), "attempt to join with thread twice"); END;<BR>      WHILE NOT t.completed DO Wait(t, t.join) END;<BR>      res := t.result;<BR>      t.result := NIL;<BR>      t.joined := TRUE;<BR>      t.join := NIL;<BR>    END;<BR>    RETURN res;<BR>  END Join;<BR> <BR>PROCEDURE AlertJoin(t: T): REFANY RAISES {Alerted} = similar<BR><BR><BR>ThreadPThread.m3:<BR> <BR><BR>PROCEDURE Join (t: T): REFANY =<BR>  BEGIN<BR>    LOCK t DO<BR>      WHILE NOT t.completed DO Wait(t, t.join) END;<BR>    END;<BR>    RETURN t.result;<BR>  END Join;<BR> <BR>PROCEDURE AlertJoin (t: T): REFANY RAISES {Alerted} = similar<BR><BR> <BR>Should we just loosen the comment and go with the simpler pthread version?<BR>I'd like Win32 and pthread to be more similar where possible, to ease maintenance.<BR> <BR> <BR> - Jay<BR></DIV></SPAN></BLOCKQUOTE></DIV><BR></DIV></DIV></SPAN><BR class=ecxApple-interchange-newline></BLOCKQUOTE></DIV><BR>                                          </body>
</html>