<HTML><HEAD>
<STYLE><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></STYLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-15">
<META content="MSHTML 6.00.6002.18100" name=GENERATOR></HEAD>
<BODY class=hmmessage>
<DIV>Understand the part about being "torn".</DIV>
<DIV> </DIV>
<DIV>I for one, have always programmed with the understanding that the comment was enforced.</DIV>
<DIV> </DIV>
<DIV>IMO: If one needs to pass the result of a thread outside the thread's context, one should use an explicit mechanism or data structure (e.g., conditions, object data fields, etc.).</DIV>
<DIV> </DIV>
<DIV>If multiple threads need to wait for a thread to finish, that is the whole concept of a rendevous (see the "Little Book of Semaphores" you referenced earlier). </DIV>
<DIV> </DIV>
<DIV>If programmers must depend on multiple joins, when is it ever safe for the underlying infrastructure to "forget about" the dead thread and its return value(s), if any? At what point has it been "too long" for you to query about a dead thread's status/return values (millisecs, minutes, hours, days, weeks -- for long-running programs this can be problematic).</DIV>
<DIV> </DIV>
<DIV>I would argue that it is better for the programmer to be explicit in such matters. It is easy enough to implement given the capabilities of the language, and indeed, I've done so many times.</DIV>
<DIV> </DIV>
<DIV>Regards,</DIV>
<DIV>Randy Coleburn<BR><BR>>>> Jay K <jay.krell@cornell.edu> 11/3/2009 10:04 AM >>><BR>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></DIV>
<DIV>
<HR id=stopSpelling>
</DIV>
<DIV>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>
<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 class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV style="WORD-WRAP: break-word"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV style="WORD-WRAP: break-word"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV><FONT class=ecxApple-style-span face="'Gill Sans'" color=#0000ff><SPAN class=ecxApple-style-span style="FONT-SIZE: medium">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 class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: medium Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV class=ecxhmmessage style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"> > (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 class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV style="WORD-WRAP: break-word"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV style="WORD-WRAP: break-word"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate"><SPAN class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: 12px Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV><FONT class=ecxecxApple-style-span color=#0000ff><FONT class=ecxecxApple-style-span face="Gill Sans"><SPAN class=ecxecxApple-style-span style="COLOR: rgb(0,0,255); FONT-FAMILY: 'Gill Sans'"><SPAN class=ecxecxApple-style-span style="COLOR: rgb(0,0,255); FONT-FAMILY: 'Gill Sans'">Antony Hosking</SPAN></SPAN></FONT></FONT><FONT class=ecxecxApple-style-span face="Gill Sans"><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: 'Gill Sans'"><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: 'Gill Sans'"><SPAN class=ecxecxApple-converted-space> </SPAN>|<SPAN class=ecxecxApple-converted-space> </SPAN></SPAN></SPAN><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: 'Gill Sans'"><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: 'Gill Sans'">Associate Professor</SPAN></SPAN><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: 'Gill Sans'"><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: 'Gill Sans'"> | Computer Science | Purdue University</SPAN></SPAN></FONT></DIV>
<DIV><FONT class=ecxecxApple-style-span face=GillSans-Light><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: GillSans-Light">305 N. University Street | West Lafayette | IN 47907 | USA</SPAN></FONT></DIV>
<DIV><FONT class=ecxecxApple-style-span face="Gill Sans" color=#0000ff><SPAN class=ecxecxApple-style-span style="COLOR: rgb(0,0,255); FONT-FAMILY: 'Gill Sans'"><SPAN class=ecxecxApple-style-span style="COLOR: rgb(0,0,255); FONT-FAMILY: 'Gill Sans'">Office</SPAN></SPAN></FONT><FONT class=ecxecxApple-style-span face=GillSans-Light><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: GillSans-Light"><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: GillSans-Light"> +1 765 494 6001 |<SPAN class=ecxecxApple-converted-space> </SPAN></SPAN></SPAN></FONT><FONT class=ecxecxApple-style-span face="Gill Sans" color=#0000ff><SPAN class=ecxecxApple-style-span style="COLOR: rgb(0,0,255); FONT-FAMILY: 'Gill Sans'"><SPAN class=ecxecxApple-style-span style="COLOR: rgb(0,0,255); FONT-FAMILY: 'Gill Sans'">Mobile</SPAN></SPAN></FONT><FONT class=ecxecxApple-style-span face=GillSans-Light><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: GillSans-Light"><SPAN class=ecxecxApple-style-span style="FONT-FAMILY: GillSans-Light"><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 class=ecxecxApple-style-span style="WORD-SPACING: 0px; FONT: medium Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV class=ecxecxhmmessage style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">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>