<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div><span class="Apple-style-span" style="font-size: medium; ">On 3 Nov 2009, at 10:49, Randy Coleburn wrote:</span></div></span></span></span></span></span></span></span></span></div></span></div></span></div><div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; "><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></span></blockquote><div><br></div><div>Agreed.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; "><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></span></blockquote><div><br></div><div>We can forget about the dead thread only when it is GC'd.  No-one can call Join without a reference to it.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; "><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></span></blockquote><div><br></div><div>Agreed.  The odd thing is just that the old "reference" user-level threads implementation never did the check, and permitted multiple joins.  And the threads spec in SPwM3 is silent on the issue.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; "><div>Regards,</div><div>Randy Coleburn<br><br>>>> Jay K <<a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>> 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:<span class="Apple-converted-space"> </span><a href="mailto:rcoleburn@scires.com">rcoleburn@scires.com</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><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 <<a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a>> 11/2/2009 11:54 PM >>><br></div><div><span class="ecxApple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal medium/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal 12px/normal 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: normal normal normal medium/normal 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></div></span><br class="Apple-interchange-newline"></blockquote></div><br></body></html>