I don't know why it doesn't return the value that I type in. I know it's not the void* arg
because it prints the right number, but I don't have any idea.
CODE:
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/types.h>
void* stampa(void* arg) {
float dato = *(float*)arg;
printf("Read: %f\n", dato);
pthread_exit((void*)&dato);
}
// Main
int main() {
system("clear");
pthread_t miot;
int creathread;
float x;
float *status;
printf("Number: ");
scanf("%f", &x);
creathread = pthread_create(&miot, NULL, stampa, (void*)&x);
if (creathread != 0) {
printf("Error\n");
}
pthread_join(miot, (void*)&status);
printf("Returned: %f\n", *status);
return 0;
}
RESULT:
Number: 10
Read: 10.000000
Returned: 0.000000