Skip to content

[BUG]The destructor of the thread_local object is not called when the thread terminates. #2220

@vmwalker

Description

@vmwalker

Description

When I use a static thread_local object in thread, the object's destructor is not called after the thead exit. The sample code is as follow. Is ndk don't support TLS?

static void threadLocalTest() {
    class Demo {
    public:
        Demo() {
            ALOGD("Demo()");
        }
        ~Demo() {
            ALOGD("~Demo()");
        }
    };

    auto func = []() {
        static thread_local Demo demo;
    };

    std::thread t1(func);
    std::thread t2(func);
    t1.join();
    t2.join();
}

Environment Details:
NDK Version: 29.0.14206865
Build sytem: cmake 3.31.6
Host OS: Windows
Compiler: Clang
ABI: arm64-v8a
STL: c++_shared
NDK API level:
Device API level: 36

I am using a supported NDK

  • I have checked and the NDK I'm using is currently supported

Affected versions

r29, r28

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions