1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

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(). :^)
This commit is contained in:
Andreas Kling 2019-11-14 20:58:23 +01:00
parent c6a8b95643
commit 69efa3f630
9 changed files with 117 additions and 5 deletions

25
Userland/tt.cpp Normal file
View file

@ -0,0 +1,25 @@
#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;
}