[cfe-dev] ThreadSanitizer in 3.5 nightly appears to incorrectly schedule calls to atexit handlers

Alexey Samsonov vonosmas at gmail.com
Thu Aug 21 15:18:10 PDT 2014


I think you are right, and this is a bug in TSan. I've filed
https://code.google.com/p/thread-sanitizer/issues/detail?id=74


On Thu, Aug 21, 2014 at 12:03 PM, Andrew C. Morrow <
andrew.c.morrow at gmail.com> wrote:

>
> Hi -
>
> I'm using the clang 3.5 builds from http://llvm.org/apt/ on Ubuntu 14.04:
>
> $clang --version
> Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
> Target: x86_64-pc-linux-gnu
> Thread model: posix
>
> The following program calls the Logger destructor after calling the
> registered atexit handler, since the logger object was constructed before
> the call to atexit:
>
> $ cat ./tsan_vs_atexit.cpp
> #include <cstdio>
> #include <cstdlib>
>
> class Logger {
> public:
>     Logger() {
>         std::printf("Logger ctor\n");
>     }
>
>     void log(const char* msg) {
>         std::printf("%s", msg);
>     }
>
>     ~Logger() {
>         std::printf("Logger dtor\n");
>     }
> };
>
> Logger logger;
>
> void log_from_atexit() {
>     logger.log("In log_from_atexit\n");
> }
>
> int main(int argc, char* argv[]) {
>     std::atexit(log_from_atexit);
>     return EXIT_SUCCESS;
> }
>
> $ clang++ -std=c++03 -fPIE -pie ./tsan_vs_atexit.cpp
> $ ./a.out
> Logger ctor
> In log_from_atexit
> Logger dtor
>
> However, if I enable the thread sanitizer, now the atexit call is
> sequenced after the call to destroy logger.
>
> $ clang++ -std=c++03 -fPIE -pie -fsanitize=thread ./tsan_vs_atexit.cpp
> $ ./a.out
> Logger ctor
> Logger dtor
> In log_from_atexit
>
> Unless I've misunderstood the C++03 language around std::atexit that
> ordering is incorrect.
>
> 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?
>
> Thanks,
> Andrew
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>


-- 
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140821/17613d32/attachment.html>


More information about the cfe-dev mailing list