[flang] Fix length handling in character kind implicit conversion (#74586)
[llvm-project.git] / libc / test / integration / src / threads / thrd_exit_test.cpp
blob0939a7621f443c4042f4a5b93babab0fdb352f49
1 //===-- Tests for thrd_exit -----------------------------------------------===//
2 //
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
6 //
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"
14 #include <threads.h>
16 bool dtor_called = false;
18 class A {
19 int val;
21 public:
22 A(int i) { val = i; }
24 void set(int i) { val = i; }
26 ~A() {
27 val = 0;
28 dtor_called = true;
32 thread_local A thread_local_a(123);
34 int func(void *) {
35 thread_local_a.set(321);
36 LIBC_NAMESPACE::thrd_exit(0);
37 return 0;
40 TEST_MAIN() {
41 thrd_t th;
42 int retval;
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);
49 return 0;
52 extern "C" {
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);