ladybird/Userland/tt.cpp
Andreas Kling 69efa3f630 Kernel+LibPthread: Implement pthread_join()
It's now possible to block until another thread in the same process has
exited. We can also retrieve its exit value, which is whatever value it
passed to pthread_exit(). :^)
2019-11-14 20:58:23 +01:00

26 lines
626 B
C++

#include <pthread.h>
#include <stdio.h>
int main(int, char**)
{
printf("Hello from the first thread!\n");
pthread_t thread_id;
int rc = pthread_create(&thread_id, nullptr, [](void*) -> void* {
printf("Hi there, from the second thread!\n");
pthread_exit((void*)0xDEADBEEF);
return nullptr;
}, nullptr);
if (rc < 0) {
perror("pthread_create");
return 1;
}
void* retval;
rc = pthread_join(thread_id, &retval);
if (rc < 0) {
perror("pthread_join");
return 1;
}
printf("Okay, joined and got retval=%p\n", retval);
return 0;
}