[llvm-dev] question about xray tls data initialization
comic fans via llvm-dev
llvm-dev at lists.llvm.org
Thu Nov 16 05:44:35 PST 2017
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 ?
More information about the llvm-dev
mailing list