<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
To answer part of my question the same as you did, this (buggy -- race conditions) program demonstrates that Alert is catchable, whereas apparently pthread_cancel is not.<br><br><br>MODULE Main;<br>IMPORT IO, Thread;<br><br>PROCEDURE ThreadMain (<* UNUSED *> closure: Thread.Closure): REFANY =<br>VAR i := 0;<br>BEGIN<br> TRY<br> LOOP<br> TRY<br> Thread.AlertPause(0.01D0);<br> IO.PutInt(i);<br> IO.Put("\n");<br> EXCEPT Thread.Alerted =><br> IO.Put("Thread.Alerted 1\n");<br> INC(i, 1);<br> IF i = 10 THEN<br> (*RAISE Thread.Alerted;*)<br> RETURN NIL;<br> END;<br> ELSE<br> IO.Put("Thread.Alerted 3?\n");<br> END<br> END;<br> FINALLY<br> IO.Put("Thread.Alerted 2\n");<br> END;<br> RETURN NIL;<br>END ThreadMain;<br><br>VAR a := Thread.Fork(NEW(Thread.Closure, apply := ThreadMain));<br>BEGIN<br>FOR i := 1 TO 10 DO<br> Thread.Pause(1.0D0);<br> Thread.Alert(a);<br>END;<br>EVAL Thread.Join(a);<br>END Main.<br><br>Thanks,<br> - Jay<br><br><br><hr id="stopSpelling">CC: m3devel@elegosoft.com<br>From: hosking@cs.purdue.edu<br>To: jay.krell@cornell.edu<br>Subject: Re: <br>Date: Mon, 7 Sep 2009 11:17:50 -0400<br><br>Jay,<div><br></div><div>Before you go off half cocked and brew up some new threads system might I suggest that it would be better to find and fix the current problem. I am sceptical that there is a much thinner M3 thread implementation on top of pthreads than we currently have. I am in the process of tracking down the problem on I386_DARWIN (I see at least one thing broken right now, and will have a fix soon).</div><div><br></div><div>In answer to your question, the wait list is to deal with M3 alerts, which are not the same as pthread cancellation.</div><div><br><div> <span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="word-wrap: break-word;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="word-wrap: break-word;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div><font class="EC_Apple-style-span" color="#0000ff"><font class="EC_Apple-style-span" face="Gill Sans"><span class="EC_Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans';"><span class="EC_Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans';">Antony Hosking</span></span></font></font><font class="EC_Apple-style-span" face="Gill Sans"><span class="EC_Apple-style-span" style="font-family: 'Gill Sans';"><span class="EC_Apple-style-span" style="font-family: 'Gill Sans';"><span class="EC_Apple-converted-space"> </span>|<span class="EC_Apple-converted-space"> </span></span></span><span class="EC_Apple-style-span" style="font-family: 'Gill Sans';"><span class="EC_Apple-style-span" style="font-family: 'Gill Sans';">Associate Professor</span></span><span class="EC_Apple-style-span" style="font-family: 'Gill Sans';"><span class="EC_Apple-style-span" style="font-family: 'Gill Sans';"> | Computer Science | Purdue University</span></span></font></div><div><font class="EC_Apple-style-span" face="GillSans-Light"><span class="EC_Apple-style-span" style="font-family: GillSans-Light;">305 N. University Street | West Lafayette | IN 47907 | USA</span></font></div><div><font class="EC_Apple-style-span" color="#0000ff" face="Gill Sans"><span class="EC_Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans';"><span class="EC_Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans';">Office</span></span></font><font class="EC_Apple-style-span" face="GillSans-Light"><span class="EC_Apple-style-span" style="font-family: GillSans-Light;"><span class="EC_Apple-style-span" style="font-family: GillSans-Light;"> +1 765 494 6001 |<span class="EC_Apple-converted-space"> </span></span></span></font><font class="EC_Apple-style-span" color="#0000ff" face="Gill Sans"><span class="EC_Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans';"><span class="EC_Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans';">Mobile</span></span></font><font class="EC_Apple-style-span" face="GillSans-Light"><span class="EC_Apple-style-span" style="font-family: GillSans-Light;"><span class="EC_Apple-style-span" style="font-family: GillSans-Light;"><span class="EC_Apple-converted-space"> </span>+1 765 427 5484</span></span></font></div><div><font class="EC_Apple-style-span" face="GillSans-Light"><br class="EC_khtml-block-placeholder"></font></div></span></span></span></span></span></span></span><br class="EC_Apple-interchange-newline"></span></div></span></div></span><br class="EC_Apple-interchange-newline"> </div><br><div><div>On 7 Sep 2009, at 05:33, Jay K wrote:</div><br class="EC_Apple-interchange-newline"><blockquote><span class="EC_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; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div class="EC_hmmessage" style="font-size: 10pt; font-family: Verdana;">Tony, can you..um, trick question sort of, briefly explain the differences between pthreads and Modula-3 threads?<br>The "trick" part is that, to an audience (me) who is not all that familiar with the nuances of either?<br>I'll see if I can find my green book and other reference material (online).<br><br><br>I understand the basics of threading very well, if that helps.<br>Eh, not much to it really.<br><br><br>I'm not super familiar with condition variables, as Win32 didn't historically have them.<br>But I think I understand them.<br><br><br>Specific questions:<br> Can Modula-3 threads be implemented more directly upon pthreads?<br><br><br> Why do we need to maintain a waiting list?<br><br><br> Is "alert" the same as "cancel" in pthread vocabulary? Or almost the same?<br><br><br> I understand..there might be a difficult problem..does Modula-3 allow catching an alert? I think so.<br> Does Posix allow canceling a cancel? I think not.<br><br><br> Posix allows, what I think of as try/finally, for alert. Modula-3 probably does too. Even though you can't stop the cancel, you can run "cleanup" code that runs before the cancel completes.<br><br><br>However mapping Modula-3 to Posix here would be tricky. As I see things..any function with a try/finally would have to be contorted into a form that passes a pointer to itself, along with parameters, to C code that does pthread_cleanup_push/pop around calling the function pointer. At least given the Darwin implementation. Other implementations might simply be able to call push at the start and pop at the end. But on Darwin these functions are macros where push introduces a local variable that pop references. I guess maybe one could to the "reverse engineering" approach (just by reading the header). But it'd still be ugly.<br><br><br>I have to do more research here.<br><br><br>I'm seriously consider "writing" a ThreadPThreadDirect.m3 that is thinner than the current ThreadPThread.m3 and see how it fairs, specifically if the Juno hangs go away.<br>"writing" being an exaggeration because it should be very small.<br><br><br>Thanks,<br> - Jay<br><br></div></span></blockquote></div><br></div></body>
</html>