1 //===-- Tests for thrd_exit -----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/threads/thrd_create.h"
10 #include "src/threads/thrd_exit.h"
11 #include "src/threads/thrd_join.h"
12 #include "test/IntegrationTest/test.h"
16 bool dtor_called
= false;
24 void set(int i
) { val
= i
; }
32 thread_local A
thread_local_a(123);
35 thread_local_a
.set(321);
36 LIBC_NAMESPACE::thrd_exit(0);
44 ASSERT_EQ(LIBC_NAMESPACE::thrd_create(&th
, func
, nullptr), thrd_success
);
45 ASSERT_EQ(LIBC_NAMESPACE::thrd_join(th
, &retval
), thrd_success
);
47 ASSERT_TRUE(dtor_called
);
48 LIBC_NAMESPACE::thrd_exit(0);
54 using Destructor
= void(void *);
56 int __cxa_thread_atexit_impl(Destructor
*, void *, void *);
58 // We do not link integration tests to C++ runtime pieces like the libcxxabi.
59 // So, we provide our own simple __cxa_thread_atexit implementation.
60 int __cxa_thread_atexit(Destructor
*dtor
, void *obj
, void *) {
61 return __cxa_thread_atexit_impl(dtor
, obj
, nullptr);