#include "src/pthread/pthread_create.h"
#include "src/pthread/pthread_exit.h"
#include "src/pthread/pthread_join.h"
#include "test/IntegrationTest/test.h"
#include <pthread.h>
bool dtor_called = false;
class A {
int val;
public:
A(int i) { val = i; }
void set(int i) { val = i; }
~A() {
val = 0;
dtor_called = true;
}
};
thread_local A thread_local_a(123);
void *func(void *) {
thread_local_a.set(321);
LIBC_NAMESPACE::pthread_exit(nullptr);
return nullptr;
}
TEST_MAIN() {
pthread_t th;
void *retval;
ASSERT_EQ(LIBC_NAMESPACE::pthread_create(&th, nullptr, func, nullptr), 0);
ASSERT_EQ(LIBC_NAMESPACE::pthread_join(th, &retval), 0);
ASSERT_TRUE(dtor_called);
LIBC_NAMESPACE::pthread_exit(nullptr);
return 0;
}
extern "C" {
using Destructor = void(void *);
int __cxa_thread_atexit_impl(Destructor *, void *, void *);
int __cxa_thread_atexit(Destructor *dtor, void *obj, void *) {
return __cxa_thread_atexit_impl(dtor, obj, nullptr);
}
}