Call __cxa_thread_finalize for the main thread.
Bug: http://b/20231984
Bug: http://b/16696563
Change-Id: I71cfddd0d404d1d4a593ec8d3bca9741de8cb90f
diff --git a/tests/__cxa_thread_atexit_test.cpp b/tests/__cxa_thread_atexit_test.cpp
index fea60b7..59d2efd 100644
--- a/tests/__cxa_thread_atexit_test.cpp
+++ b/tests/__cxa_thread_atexit_test.cpp
@@ -50,6 +50,29 @@
ASSERT_EQ("dtor called.", class_with_dtor_output);
}
+class ClassWithDtorForMainThread {
+ public:
+ void set_message(const std::string& msg) {
+ message = msg;
+ }
+
+ ~ClassWithDtorForMainThread() {
+ fprintf(stderr, "%s", message.c_str());
+ }
+ private:
+ std::string message;
+};
+
+static void thread_atexit_main() {
+ static thread_local ClassWithDtorForMainThread class_with_dtor_for_main_thread;
+ class_with_dtor_for_main_thread.set_message("d-tor for main thread called.");
+ exit(0);
+}
+
+TEST(thread_local, dtor_for_main_thread) {
+ ASSERT_EXIT(thread_atexit_main(), testing::ExitedWithCode(0), "d-tor for main thread called.");
+}
+
extern "C" int __cxa_thread_atexit_impl(void (*fn)(void*), void* arg, void* dso_handle);
static void thread_atexit_fn1(void* arg) {