[llvm-dev] question about xray tls data initialization

Dean Michael Berris via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 21 03:46:27 PST 2017


> On 17 Nov 2017, at 00:44, comic fans via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> I'm learning the xray library and try if it can be built on windows,  in
> xray_fdr_logging_impl.h
> 
> line 152  , comment written as
> // Using pthread_once(...) to initialize the thread-local data structures
> 
> 
> but at line 175, 183, code written as
> 
> thread_local pthread_key_t key;
> 
>  // Ensure that we only actually ever do the pthread initialization once.
>  thread_local bool UNUSED Unused = [] {
>    new (&TLSBuffer) ThreadLocalData();
>    auto result = pthread_key_create(&key, +[](void *) {
>      auto &TLD = *reinterpret_cast<ThreadLocalData *>(&TLSBuffer);
> 
> 
> I'm confused that pthread_key_t and Unused are both thread_local
> variable, doesn't it mean the following lambda will run for each
> thread , and create one pthread_key_t for only one tls data(instead of
> only one pthread_key_t for all thread) ? also what does the '+' before
> lambda expression mean ?  this may be stupid questions, could somebody
> kindly  helped ?

Yeah, that comment is out-of-date (and the implementation is buggy) -- which is a shame really. :/

But, the good news, is I think we've fixed this now in the top-of-trunk with https://reviews.llvm.org/D39526 <https://reviews.llvm.org/D39526> and https://reviews.llvm.org/D40164 <https://reviews.llvm.org/D40164>.

Curiously though, how far did your exploration into getting XRay to build on Windows go?

Cheers

-- Dean

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171121/02a7503b/attachment.html>


More information about the llvm-dev mailing list