<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=iso-8859-1">
<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 Eliot, Nicolas, all,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I've been circling around a question how to terminate, i.e. unwind a process sitting at a condition variable inside an unwind block:
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The old suspend primitive 88 unblocks the process and the unwind can proceed. The new suspend primitive 568/578 on the other hand backs it up before the wait send which means the unwind in such case won't proceed far - it will get sat back
 to the wait. It looks like for termination/unwind purposes it's more convenient to use the old prim 88 (called from e.g. suspendAndUnblock method Nicolas suggested). Just making sure I haven't overlooked anything.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Now, if the process gets unblocked from the condition variable, the unwind would proceed *as if* the process got a signal on the condition variable. I've sent a question to the dev-list about such unblocking in case of a mutex. It looks
 suspicious that a process continues into the critical block without acquiring the ownership and even niling the existing ownership. I'm not sure I understand the Mutex correctly though. Here's the test:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">testMutexBlockedInCritical          "self run: #testMutexBlockedInCritical"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                | lock sock proc wait |<o:p></o:p></p>
<p class="MsoNormal">                lock := Mutex new.<o:p></o:p></p>
<p class="MsoNormal">                sock := Semaphore new.<o:p></o:p></p>
<p class="MsoNormal">                proc := [lock critical: [sock wait]] fork.<o:p></o:p></p>
<p class="MsoNormal">                wait := [[] ensure: [lock critical: []]] fork.  "<---- important"<o:p></o:p></p>
<p class="MsoNormal">                Processor yield.<o:p></o:p></p>
<p class="MsoNormal">                self assert: proc suspendingList == sock.<o:p></o:p></p>
<p class="MsoNormal">                self assert: wait suspendingList == lock.<o:p></o:p></p>
<p class="MsoNormal">                self deny: lock isEmpty.<o:p></o:p></p>
<p class="MsoNormal">                self assert: lock isOwned.<o:p></o:p></p>
<p class="MsoNormal">                wait terminate.<o:p></o:p></p>
<p class="MsoNormal">                Processor yield.<o:p></o:p></p>
<p class="MsoNormal">                self assert: wait isTerminated.<o:p></o:p></p>
<p class="MsoNormal">                self assert: proc suspendingList == sock.<o:p></o:p></p>
<p class="MsoNormal">                self assert: wait suspendingList == nil.<o:p></o:p></p>
<p class="MsoNormal">                self assert: lock isEmpty.<o:p></o:p></p>
<p class="MsoNormal">                self deny: lock isOwned            "<---- is this right???"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Similarly, this modified Semaphore test fails too:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">testSemaInCriticalWait2                "self run: #testSemaInCriticalWait"<o:p></o:p></p>
<p class="MsoNormal">                "This tests whether a semaphore that has entered the wait in Semaphore>>critical:<o:p></o:p></p>
<p class="MsoNormal">                leaves it without signaling the associated semaphore."<o:p></o:p></p>
<p class="MsoNormal">                | s p |<o:p></o:p></p>
<p class="MsoNormal">                s := Semaphore new.<o:p></o:p></p>
<p class="MsoNormal">                p := [[] ensure: [s critical:[]]] fork.   "<---- important"<o:p></o:p></p>
<p class="MsoNormal">                Processor yield.<o:p></o:p></p>
<p class="MsoNormal">                self assert:(p suspendingList == s).<o:p></o:p></p>
<p class="MsoNormal">                p terminate.<o:p></o:p></p>
<p class="MsoNormal">                self assert: 0 equals: s excessSignals        "<---- s will have 1 excess signal!!!"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is this something to worry about? How should a process unblocked from a condition variable continue, actually? Or maybe just in case of critical sections the behavior could be restricted, e.g. to avoid evaluating the critical section?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks for any comments,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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>