[PATCH] D38073: [XRay][compiler-rt] Use pthread for initializing thread-local data

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 00:23:42 PDT 2017


dberris created this revision.

We avoid using C++11's thread_local keyword on non-trivially
destructible objects because it may introduce deadlocks when the C++
runtime registers destructors calling std::malloc(...). The deadlock may
happen when the allocator implementation is itself XRay instrumented.

To avoid having to call malloc(...) and free(...) in particular, we use
pthread_once, pthread_create_key, and pthread_setspecific to instead
manually register the cleanup implementation we want.

The code this replaces used an RAII type that implements the cleanup
functionality in the destructor, that was then initialized as a
function-local thread_local object. While it works in usual situations,
unfortunately it breaks when using a malloc implementation that itself
is XRay-instrumented.


https://reviews.llvm.org/D38073

Files:
  lib/xray/xray_fdr_logging_impl.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38073.115967.patch
Type: text/x-patch
Size: 6583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170920/f388d495/attachment.bin>


More information about the llvm-commits mailing list