[M3devel] awful race condition in libm3/FilePosix.m3?

Jay K jay.krell at cornell.edu
Wed Jan 30 08:40:02 CET 2013


FilePosix.m3:


I'm not 100% sure, but looks really bad.
I suspect it will close arbitrary files out from other threads.
Notice there is absolutely no mutual exclusion.
An arbitrary number of threads will run here, mostly succeeding, but not necessarily.

VAR
  null_done := FALSE;
  null_stat: Ustat.struct_stat;
  null_fd: INTEGER;


PROCEDURE IsDevNull(READONLY statbuf: Ustat.struct_stat): BOOLEAN RAISES {} =
  VAR result: INTEGER;
  BEGIN
    IF NOT null_done THEN
      null_fd := Unix.open(M3toC.FlatTtoS("/dev/null"), Unix.O_RDONLY, Unix.Mrwrwrw);
      IF null_fd < 0 THEN
        null_done := TRUE;
        RETURN FALSE
      ELSE
        result := Ustat.fstat(null_fd, ADR(null_stat));
        EVAL Unix.close(null_fd);
        IF result # 0 THEN
          null_fd := -1
        END
      END;
      null_done := TRUE;
    END;
    RETURN null_fd >= 0 AND statbuf.st_rdev = null_stat.st_rdev
  END IsDevNull;


 - Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20130130/60d6374f/attachment-0001.html>


More information about the M3devel mailing list