mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 10:19:03 +03:00
69efa3f630
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(). :^)
26 lines
626 B
C++
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;
|
|
}
|