diff --git a/absl/base/internal/thread_identity.h b/absl/base/internal/thread_identity.h index b6e917ce..acfc15a8 100644 --- a/absl/base/internal/thread_identity.h +++ b/absl/base/internal/thread_identity.h @@ -130,7 +130,11 @@ struct PerThreadSynch { }; // The instances of this class are allocated in NewThreadIdentity() with an -// alignment of PerThreadSynch::kAlignment. +// alignment of PerThreadSynch::kAlignment and never destroyed. Initialization +// should happen in OneTimeInitThreadIdentity(). +// +// Instances may be reused by new threads - fields should be reset in +// ResetThreadIdentityBetweenReuse(). // // NOTE: The layout of fields in this structure is critical, please do not // add, remove, or modify the field placements without fully auditing the diff --git a/absl/synchronization/internal/create_thread_identity.cc b/absl/synchronization/internal/create_thread_identity.cc index eacaa28d..93cd376b 100644 --- a/absl/synchronization/internal/create_thread_identity.cc +++ b/absl/synchronization/internal/create_thread_identity.cc @@ -39,7 +39,8 @@ ABSL_CONST_INIT static base_internal::SpinLock freelist_lock( ABSL_CONST_INIT static base_internal::ThreadIdentity* thread_identity_freelist; // A per-thread destructor for reclaiming associated ThreadIdentity objects. -// Since we must preserve their storage we cache them for re-use. +// Since we must preserve their storage, we cache them for re-use instead of +// truly destructing the object. static void ReclaimThreadIdentity(void* v) { base_internal::ThreadIdentity* identity = static_cast(v); @@ -124,6 +125,9 @@ static base_internal::ThreadIdentity* NewThreadIdentity() { identity = reinterpret_cast( RoundUp(reinterpret_cast(allocation), base_internal::PerThreadSynch::kAlignment)); + // Note that *identity is never constructed. + // TODO(b/357097463): change this "one time init" to be a proper + // constructor. OneTimeInitThreadIdentity(identity); } ResetThreadIdentityBetweenReuse(identity);