379_demos/lab4/demos/pthread_exit_status.c
2024-10-08 16:50:03 -06:00

32 lines
788 B
C

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* integer_return(void* arg) {
return (void*) 1;
}
void* string_return(void* arg) {
char* string = calloc(4, sizeof(char));
string[0] = 'c';
string[1] = 'a';
string[2] = 't';
pthread_exit((void*) string);
}
int main(void) {
pthread_t thread_id_1;
pthread_t thread_id_2;
pthread_create(&thread_id_1, NULL, integer_return, NULL);
pthread_create(&thread_id_2, NULL, string_return, NULL);
void* thread_return_value;
pthread_join(thread_id_1, &thread_return_value);
printf("The first thread returned: %d\n", *(int*) thread_return_value);
pthread_join(thread_id_2, &thread_return_value);
printf("The second thread returned: %s\n", (char*) thread_return_value);
}