<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'>I commited a fix. But two questions:<br><br>1) why not just stat, instead of open, fstat, close?<br><br>2) a lighter weight way to fix this than I did?<br>In particular:<br>a) VAR m := NEW(MUTEX);<br>can we at least say VAR m: MUTEX instead? I tried. It crashed.<br><br>b) some notion of a "once"? a lock that will only be successfully entered once, for one-time initialization, all other attempts to enter wait for the first enterer to leave, and the it is never entered again. pthreads has this. Win32 since Vista has it (I'd still provide something compatible to pre-Vista, but it can be done easily enough.<br>They are faster and perhaps smaller than other kinds of locks.<br><br> - Jay<br><br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: jay.krell@cornell.edu<br>To: m3devel@elegosoft.com<br>Date: Wed, 30 Jan 2013 07:40:02 +0000<br>Subject: [M3devel] awful race condition in libm3/FilePosix.m3?<br><br>

<style><!--
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:12pt;font-family:Calibri;}

--></style>
<div dir="ltr">FilePosix.m3:<br><br><br>I'm not 100% sure, but looks really bad.<br>I suspect it will close arbitrary files out from other threads.<br>Notice there is absolutely no mutual exclusion.<br>An arbitrary number of threads will run here, mostly succeeding, but not necessarily.<br><br>VAR<br>  null_done := FALSE;<br>  null_stat: Ustat.struct_stat;<br>  null_fd: INTEGER;<br><br><br>PROCEDURE IsDevNull(READONLY statbuf: Ustat.struct_stat): BOOLEAN RAISES {} =<br>  VAR result: INTEGER;<br>  BEGIN<br>    IF NOT null_done THEN<br>      null_fd := Unix.open(M3toC.FlatTtoS("/dev/null"), Unix.O_RDONLY, Unix.Mrwrwrw);<br>      IF null_fd < 0 THEN<br>        null_done := TRUE;<br>        RETURN FALSE<br>      ELSE<br>        result := Ustat.fstat(null_fd, ADR(null_stat));<br>        EVAL Unix.close(null_fd);<br>        IF result # 0 THEN<br>          null_fd := -1<br>        END<br>      END;<br>      null_done := TRUE;<br>    END;<br>    RETURN null_fd >= 0 AND statbuf.st_rdev = null_stat.st_rdev<br>  END IsDevNull;<br><br><br> - Jay<br>                                         </div></div>                                        </div></body>
</html>