<div dir="ltr">I think you are right, and this is a bug in TSan. I've filed <a href="https://code.google.com/p/thread-sanitizer/issues/detail?id=74">https://code.google.com/p/thread-sanitizer/issues/detail?id=74</a></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 21, 2014 at 12:03 PM, Andrew C. Morrow <span dir="ltr"><<a href="mailto:andrew.c.morrow@gmail.com" target="_blank">andrew.c.morrow@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Hi -</div><div><br></div><div>I'm using the clang 3.5 builds from <a href="http://llvm.org/apt/" target="_blank">http://llvm.org/apt/</a> on Ubuntu 14.04:</div>
<div><br></div><div>$clang --version</div>
<div><div>Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)</div><div>Target: x86_64-pc-linux-gnu</div><div>Thread model: posix</div></div><div><br></div><div>The following program calls the Logger destructor after calling the registered atexit handler, since the logger object was constructed before the call to atexit:</div>

<div><br></div><div><div>$ cat ./tsan_vs_atexit.cpp</div><div>#include <cstdio></div><div>#include <cstdlib></div><div><br></div><div>class Logger {</div><div>public:</div><div>    Logger() {</div><div>        std::printf("Logger ctor\n");</div>

<div>    }</div><div><br></div><div>    void log(const char* msg) {</div><div>        std::printf("%s", msg);</div><div>    }</div><div><br></div><div>    ~Logger() {</div><div>        std::printf("Logger dtor\n");</div>

<div>    }</div><div>};</div><div><br></div><div>Logger logger;</div><div><br></div><div>void log_from_atexit() {</div><div>    logger.log("In log_from_atexit\n");</div><div>}</div><div><br></div><div>int main(int argc, char* argv[]) {</div>

<div>    std::atexit(log_from_atexit);</div><div>    return EXIT_SUCCESS;</div><div>}</div><div><br></div><div>$ clang++ -std=c++03 -fPIE -pie ./tsan_vs_atexit.cpp</div><div>$ ./a.out</div><div>Logger ctor</div><div>In log_from_atexit</div>

<div>Logger dtor</div><div><br></div><div>However, if I enable the thread sanitizer, now the atexit call is sequenced after the call to destroy logger.</div><div><br></div><div>$ clang++ -std=c++03 -fPIE -pie -fsanitize=thread ./tsan_vs_atexit.cpp</div>

<div>$ ./a.out</div><div>Logger ctor</div><div>Logger dtor</div><div>In log_from_atexit</div></div><div><br></div><div>Unless I've misunderstood the C++03 language around std::atexit that ordering is incorrect.</div>
<div>
<br></div><div>A quick google search didn't find much. Is this a known issue, or is the ordering not specified in C++03 as I thought?</div><div><br></div><div>Thanks,</div><div>Andrew</div><div><br></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div>
</div>