<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>We have race conditions, like this, m3core/src/Text.m3:<br><br><br>VAR fromCharCache := ARRAY CHAR OF T {NIL, ..}; (* 1-char texts *)<br><br><br>PROCEDURE FromChar (c: CHAR): T =<br> VAR buf: ARRAY [0..0] OF CHAR;<br> BEGIN<br> IF fromCharCache [c] = NIL THEN<br> buf [0] := c;<br> fromCharCache[c] := Text8.New (buf);<br> END;<br> RETURN fromCharCache [c]<br> END FromChar;<br><br><br>It should be:<br><br><br>PROCEDURE FromChar (c: CHAR): T =<br>
VAR buf: ARRAY [0..0] OF CHAR;<br>
BEGIN<br>
IF fromCharCache [c] = NIL THEN<br>
buf [0] := c;<br>
WITH a = Text8.New (buf) DO<br> MemoryBarrier();<br> fromCharCache[c] := a;<br> END;<br>
END;<br>
RETURN fromCharCache [c]<br>
END FromChar;<br>
<br><br>to ensure that all of Text8.New() finishes before the assignment to fromCharCache[c] is made.<br><br><br>Can the compiler somehow catch these?<br>I fear they are a small epidemic.<br>For a long time people didn't realize where all the compiler and processor could reorder.<br><br><br>Do we have the right constructs by now to fix them?<br>I think we do.<br><br><br> - Jay<br> </div></body>
</html>