[PATCH] D14288: [tsan] Alternative ThreadState storage for OS X

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 4 01:30:26 PST 2015


dvyukov added a comment.

> I see. Could you please suggest a way to make it async-signal-safe?


Something along the lines of:

thr = atomic_load(fake_tls, memory_order_relaxed);
atomic_signal_fence(memory_order_acquire); // turns the previous load into acquire wrt signals
if (thr == nullptr) {

  // slow-path
  thr = (ThreadState *)InternalAlloc(sizeof(ThreadState), nullptr);
  internal_memset(thr, 0, sizeof(*thr));
  ThreadState *cmp = nullptr;
  if (!atomic_compare_exchange_strong(fake_tls, &cmp, thr, memory_order_acq_rel)) {
      InternalFree(thr);
      thr = cmp;
  }

}
return thr;

However, InternalAlloc is not async-signal-safe (and probably needs explicit initialization, so don't work too early), so you need to replace them with internal_mmap/munmap.


http://reviews.llvm.org/D14288





More information about the llvm-commits mailing list