<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Calibri Light";
panose-1:2 15 3 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing
{mso-style-priority:1;
margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi Juan,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'm enclosing an update of #terminate and a revised version of #suspend.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">There are two main reasons for this update:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">(1) Currently the process that sends #terminate won't wait for the process being terminated to finish its termination if the process being terminated e.g. inserts a delay in an unwind block (see #testTerminateWithDelayInUnwind). To fix
this deficiency I've engaged a semaphore to synchronize the two processes. In addition, I've added a bit more powerful guard (see #unwindAndStop:) to make sure a process is correctly terminated even in case of multiple concurrent termination attempts, and
a few minor fixes for edge cases. This updated approach passed all Squeak’s and Pharo’s tests :) I'll be sending more tests later after I'll adapt my Squeak versions; apologies. (Changed methods: #terminate, #unwindTo:, #runUntilReturnFrom:; added methods:
#suspendAndReleaseCriticalSection, #unwindAndStop:)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">(2) Eliot implemented a revised process suspend semantics in primitive 578. The original suspend semantics (in primitive 88) is flawed and allows a process waiting on a semaphore (or mutex in Squeak) to leave the semaphore even without
receiving a signal: the original suspend primitive 88 simply removes the process from the semaphore. The new suspend primitive 578 backs up the process's pc by "one instruction", i.e. to the send that placed the process in the semaphore queue; it means that
when the process resumes it reenters the wait state. Check #testSuspendAndResume. (Changed methods: #suspend, #signalException:, #signalWaitingProcess; added methods: #suspendAndUnblock:, #processSuspensionUnblocks)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Both "fixes" can be implemented independently but for simplicity I'm sending them both in one package; should you decide to implement just fix at a time I can separate them.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">While the #terminate fix is just improving the current behavior (and most likely not breaking any existing code) the #suspend fix may be a bit different story:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Considerations:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">i) there may be some existing external code (ab)using the flawed behavior of primitive 88 -> for this scenario the old behavior has been retained in #suspendAndUnblock method. It may be useful but must be used with caution.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ii) there are a few methods even in the core taking advantage of the old behavior: Process >> #signalException: and DelayWaitTimeout >> #signalWaitingProcess - check the fixed code. (Cuis has also Process >> #signal but I'm not sure what
its purpose is compared to #signalException: - please advise)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">iii) in the new release VM (3185) there are in fact two new suspend primitives: #578 and #568; the only difference is the return value: #568 returns the list the suspended process was previously waiting at (the same return semantics as
primitive #88) while #578 returns nil if the process's pc was backed up; after a debate with Eliot and Nicolas, Squeak uses 578 but it's no problem to use 568 instead.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">iv) #testAtomicSuspend uses #suspendPrimitivelyOrFail - I'd suggest changing the primitive suspend to 578 and modify the test but I'm not sure how you decide to proceed; maybe test both primitives?</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">v) Eliot has also added to Squeak a new method #processSuspensionUnblocks accessing vmParameterAt: 65 which indicates whether the VM provides the new suspend primitives. I'm just mentioning it FYI and enclosing the code for your consideration
(with Eliot's authorship).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Juan, please let me know what you think and whether you plan to use the new #suspend. Thanks again for implementing the UI fixes - without them the new #terminate would freeze the UI for many innocent examples :) (...because #terminate
operates inside the ensure argument block and now *waits* there until the process being terminated finishes its termination and that would indeed freeze the UI in case of an unwind error).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If you spot any issue or inconsistency please let me know; I'll be away for a few days but back for the weekend.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best regards,</p>
<p class="MsoNormal">Jaromir</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNoSpacing"><span lang="CS">--</span></p>
<p class="MsoNoSpacing"><strong><span style="font-family:"Calibri Light",sans-serif;color:#333333;font-weight:normal">Jaromír Matas</span></strong><span style="font-family:"Calibri Light",sans-serif;color:#555555"><o:p></o:p></span></p>
<p class="MsoNoSpacing"><span style="font-family:"Calibri Light",sans-serif;color:#2E75B6">mail@jaromir.net</span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>