2024-11-20 17:55:57 +02:00
|
|
|
#include <pthread.h>
|
2024-11-20 15:39:10 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-11-20 17:55:57 +02:00
|
|
|
static void *thread(void *arg) {
|
|
|
|
pthread_t self = pthread_self();
|
|
|
|
printf("[child] pthread_self() = %u\n", self);
|
|
|
|
sleep(3);
|
|
|
|
return arg;
|
|
|
|
}
|
2024-11-20 15:39:10 +02:00
|
|
|
|
2024-11-15 23:18:04 +02:00
|
|
|
int main(int argc, const char **argv) {
|
2024-11-20 17:55:57 +02:00
|
|
|
pthread_t id;
|
|
|
|
|
|
|
|
assert(pthread_create(&id, NULL, thread, (void *) 0x1234) == 0);
|
2024-11-20 15:39:10 +02:00
|
|
|
|
2024-11-20 17:55:57 +02:00
|
|
|
pthread_t self = pthread_self();
|
|
|
|
printf("[main] pthread_self() = %u\n", self);
|
2024-11-20 15:39:10 +02:00
|
|
|
|
2024-11-20 17:55:57 +02:00
|
|
|
void *result;
|
|
|
|
assert(pthread_join(id, &result) == 0);
|
|
|
|
printf("[main] result: %p\n", result);
|
2024-11-20 15:39:10 +02:00
|
|
|
|
2024-11-11 15:19:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|