34 lines
718 B
C
34 lines
718 B
C
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
typedef struct coco {
|
|
char *name;
|
|
} Coco;
|
|
|
|
char *COCO_NAME = "COCO";
|
|
|
|
void *thread_func(void *data) {
|
|
printf("Hello from the new thread!\n");
|
|
Coco *c = malloc(sizeof(Coco));
|
|
c->name = COCO_NAME;
|
|
return c;
|
|
}
|
|
|
|
int main() {
|
|
pthread_t thread;
|
|
void *ret;
|
|
int result = pthread_create(&thread, NULL, thread_func, NULL);
|
|
if (result != 0) {
|
|
printf("Error creating thread: %d\n", result);
|
|
return 1;
|
|
}
|
|
result = pthread_join(thread, &ret);
|
|
if (result != 0) {
|
|
printf("Error joining thread: %d\n", result);
|
|
return 1;
|
|
}
|
|
printf("Hello from the main thread!\n");
|
|
printf("Return Value: %s", ((Coco *)(ret))->name);
|
|
return 0;
|
|
}
|