Files
operating-systems/chp4_threads/ex417.c
Fabio Scotto di Santolo 3c4b9bdc56 Renaming folders
2024-09-11 10:47:59 +02:00

32 lines
573 B
C

#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int value = 0;
void *runner(void *param);
int main(int argc, char *argv[]) {
pid_t pid;
pthread_t tid;
pthread_attr_t attr;
pid = fork();
if (pid == 0) {
pthread_attr_init(&attr);
pthread_create(&tid, &attr, runner, NULL);
pthread_join(tid, NULL);
printf("CHILD: value = %d\n", value);
} else if (pid > 0) {
wait(NULL);
printf("PARENT: value = %d\n", value);
}
}
void *runner(void *param) {
value = 5;
pthread_exit(0);
}