TestThread.cpp 772 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2021, Spencer Dixon <spencercdixon@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <LibThreading/Thread.h>
  8. #include <unistd.h>
  9. // FIXME: Enable these tests once they work reliably.
  10. #if 0
  11. TEST_CASE(threads_can_detach)
  12. {
  13. int should_be_42 = 0;
  14. auto thread = Threading::Thread::construct([&should_be_42]() {
  15. usleep(10 * 1000);
  16. should_be_42 = 42;
  17. return 0;
  18. });
  19. thread->start();
  20. thread->detach();
  21. usleep(20 * 1000);
  22. EXPECT(should_be_42 == 42);
  23. }
  24. TEST_CASE(joining_detached_thread_errors)
  25. {
  26. auto thread = Threading::Thread::construct([]() { return 0; });
  27. thread->start();
  28. thread->detach();
  29. EXPECT(thread->join().is_error());
  30. }
  31. #endif