<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:Helvetica;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
@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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="FR" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Nice, thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">I think this is especially useful when we must call a “blackbox library”  from finally/cleanup block (so we can’t control if the special uninterruptible versions of APIs – if they exist
 - are used inside).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Arnaud<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:35.4pt">
<b><span style="font-size:12.0pt;color:black">De : </span></b><span style="font-size:12.0pt;color:black">Ron Pressler <ron.pressler@oracle.com><br>
<b>Date : </b>mercredi, 15 mars 2023 à 16:27<br>
<b>À : </b>Arnaud Masson <arnaud.masson@fr.ibm.com><br>
<b>Cc : </b>loom-dev@openjdk.org <loom-dev@openjdk.org>, Piotr Tarsa <piotr.tarsa@gmail.com><br>
<b>Objet : </b>Re: [External] : Re: The Great Concurrency Smackdown: ZIO versus JDK by John A. De Goes<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt;mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">If you really want to run some code uninterruptibly, you’d either use an uninterruptible version of the method (which is available for some methods
 in the JDK), or protect the code from interruption by submitting it as a task and controlling
<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt;mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerStart<o:p></o:p></span></p>
</div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;margin-left:35.4pt;border-radius:4px">
<tbody>
<tr>
<td style="padding:12.0pt 0cm 12.0pt 0cm">
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%;background:#D0D8DC;border:none;border-top:solid #90A4AE 3.0pt">
<tbody>
<tr>
<td valign="top" style="border:none;padding:0cm 7.5pt 3.75pt 4.5pt">
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" align="left">
<tbody>
<tr>
<td style="padding:3.0pt 6.0pt 3.0pt 6.0pt">
<p class="MsoNormal"><b><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:black">This Message Is From an External Sender
<o:p></o:p></span></b></p>
</td>
</tr>
<tr>
<td style="padding:3.0pt 6.0pt 3.0pt 6.0pt">
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black">This message came from outside your organization.
<o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div>
<p class="MsoNormal" style="margin-left:35.4pt;mso-line-height-alt:.75pt"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerEnd<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-left:35.4pt">If you really want to run some code uninterruptibly, you’d either use an uninterruptible version of the method (which is available for some methods in the JDK), or protect the code from interruption by submitting
 it as a task and controlling it with a future. Here’s how you can implement a general `doUninterruptibly` in a similar way, only using StructuredTaskScope:
<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><o:p> </o:p></p>
</div>
<blockquote style="margin-left:30.0pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New""><T> T doUninterruptibly(Callable<T> task) throws ExecutionException {</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">    boolean interrupted = false;</span>
<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">    try (var s = new StructuredTaskScope.ShutdownOnSuccess<T>()) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">        s.fork(task);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">        while (true) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">            try {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">                return s.join().result();</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">            } catch (InterruptedException ex) {</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">                interrupted = true;</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">            }</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">        }</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">    } finally {</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">        if (interrupted) Thread.currentThread().interrupt();</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">    }</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"">}</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal" style="margin-left:35.4pt">On 15 Mar 2023, at 14:37, Arnaud Masson <<a href="mailto:arnaud.masson@fr.ibm.com">arnaud.masson@fr.ibm.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-left:35.4pt"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">Yes, that avoids problems most of the time,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">but what if closeStuff() could throw<span class="apple-converted-space"> </span>InterruptedException?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">(If the thread interruption request occurs during the finally block, not during the try block.)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US"><br>
thanks</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">Arnaud</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt">On 15 Mar 2023, at 14:15, Arnaud Masson <<a href="mailto:arnaud.masson@fr.ibm.com">arnaud.masson@fr.ibm.com</a>> wrote:<o:p></o:p></p>
</div>
</div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"> <o:p></o:p></p>
</div>
<div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">Yes, that would be nice for finally { } blocks.</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">A bit like what’s suggested here:<span class="apple-converted-space"> </span><a href="https://github.com/google/guava/issues/1409#issuecomment-389469315"><span style="color:#0563C1">https://github.com/google/guava/issues/1409#issuecomment-389469315</span></a></span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">try {</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">   doSomeIO();  // can throw InterruptedException</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">   …</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">} finally {</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">   Uninterruptibles.runUninterruptibly(() -></span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">      closeStuff() // cannot throw InterruptedException</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">   ) // auto rethrow (delayed) InterruptedException  if needed</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">}</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US">What about try-with-resource?</span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span lang="EN-US"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt">thanks<o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt">Arnaud<o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"> <o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-size:10.0pt"> </span><o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt"> <o:p></o:p></p>
</div>
</div>
<div>
<div style="margin-left:35.4pt">
<p class="MsoNormal" style="margin-left:35.4pt">Methods that throw InterruptedException clear the interrupt status precisely to allow calling interruptible methods in cleanup code.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-size:9.0pt;font-family:Helvetica">Unless otherwise stated above:<br>
<br>
Compagnie IBM France<br>
Siège Social : 17, avenue de l'Europe, 92275 Bois-Colombes Cedex<br>
RCS Nanterre 552 118 465<br>
Forme Sociale : S.A.S.<br>
Capital Social : 664 069 390,60 €<br>
SIRET : 552 118 465 03644 - Code NAF 6203Z<o:p></o:p></span></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal" style="margin-left:35.4pt"><o:p> </o:p></p>
</div>
</div>

<DIV>
Unless otherwise stated above:<BR>
<BR>
Compagnie IBM France<BR>
Siège Social : 17, avenue de l'Europe, 92275 Bois-Colombes Cedex<BR>
RCS Nanterre 552 118 465<BR>
Forme Sociale : S.A.S.<BR>
Capital Social : 664 069 390,60 €<BR>
SIRET : 552 118 465 03644 - Code NAF 6203Z<BR>
</DIV></body>
</html>