[M3devel] suspicious order of evaluation?
Jay K
jay.krell at cornell.edu
Thu Oct 25 07:42:16 CEST 2012
m3tohtml/src/Main.m3:
sources is global
PROCEDURE Add() = BEGIN sources := NEW (Source, next := sources, from := Pathname.Join(pkgpath, file, NIL), to := Pathname.Join(pkg, FixDerived (file), NIL), kind := kind);
It APPEARS this compiles to like:
temp = RTHooks__AllocateTracedRef(...); sources = temp if temp == NULL raise exception sources->from = ... sources->to = ...
To me this seems a bit suspicious.
First, the null check should be against the temp. Sources should not be assigned and then checked. Second, probably, the fields of sources should be filled in before the global. So, it should be more like:
temp = RTHooks__AllocateTracedRef(); if temp == NULL raise exception temp->from = ... temp->to = ... sources = temp ...
Just as efficient, but "safer".
Now, I realize, without a lock or barrier, the compiler is free to reorder like this.Maybe ideally temp would be gone but the original order used?
C++ would implement it more like how I showed.
Thoughts?
- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20121025/90909232/attachment-0001.html>
More information about the M3devel
mailing list