folly/folly/detail/thread_local_globals.cpp

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/detail/thread_local_globals.h>

#include <system_error>

#include <folly/detail/StaticSingletonManager.h>
#include <folly/lang/Exception.h>
#include <folly/portability/PThread.h>

namespace folly::detail {

namespace {

/// thread_is_dying_global
///
/// This is a hack. The C runtime library provides no indication that a thread
/// has ended the phase where thread_local variables may be destroyed. Were it
/// to provide that indication, that would be used instead. Relies on library
/// facilities which have signal to mark that a thread is dying.
///
/// In glibc, in the shutdown phase, start_thread first calls __call_tls_dtors,
/// which runs destructors of thread_local variables, and then immediately calls
/// __nptl_deallocate_tsd, which runs destructors of pthread thread-specific
/// variables. There is no other indication of state change in the current
/// thread.
///
/// https://github.com/bminor/glibc/blob/glibc-2.39/nptl/pthread_create.c#L451-L455
struct thread_is_dying_global {};

} // namespace

bool thread_is_dying() {}

void thread_is_dying_mark() {}

} // namespace folly::detail