···88#include <LibThreading/Thread.h>
99#include <unistd.h>
10101111-// FIXME: Enable these tests once they work reliably.
1212-1313-#if 0
1411TEST_CASE(threads_can_detach)
1512{
1613 int should_be_42 = 0;
···29263027TEST_CASE(joining_detached_thread_errors)
3128{
3232- auto thread = Threading::Thread::construct([]() { return 0; });
2929+ Atomic<bool> should_exit { false };
3030+ auto thread = Threading::Thread::construct([&]() {
3131+ while (!should_exit.load())
3232+ usleep(10 * 1000);
3333+ return 0;
3434+ });
3335 thread->start();
3436 thread->detach();
35373636- EXPECT(thread->join().is_error());
3838+ // Because of how the crash test forks and removes the thread, we can't use that to verify that join() crashes. Instead, we check the join crash condition ourselves.
3939+ EXPECT(!thread->needs_to_be_joined());
4040+4141+ // FIXME: Dropping a running thread crashes because of the Function destructor. For now, force the detached thread to exit.
4242+ should_exit.store(true);
4343+ usleep(20 * 1000);
4444+}
4545+4646+TEST_CASE(join_dead_thread)
4747+{
4848+ auto thread = Threading::Thread::construct([&]() { return 0 /*nullptr*/; });
4949+ thread->start();
5050+ // The thread should have exited by then.
5151+ usleep(40 * 1000);
5252+5353+ auto join_result = thread->join<int*>();
5454+5555+ EXPECT(!join_result.is_error());
5656+ EXPECT_EQ(join_result.value(), static_cast<int*>(0));
3757}
3838-#endif