Hello,
I hope you can help me with my problem.
I've written a programm which creates a thread. The main programmm creates 10 int and float values. The fucnction should give the values out.
May big problem ist that the delivery to the function is not working.
Where ist my fault?
How can I make easier?
Thank you for your help.
void funktion1 (void *arg1)
{
printf("Int-Zahl= %i",arg1);
printf("[TID:%li,PPID:%i] Threadfunktion1 \n",syscall(SYS_gettid),getppid() );
pthread_exit(NULL);
}
int main()
{
struct Zahlen{int z1;float z2;};
struct Zahlen Zahl;
pthread_t ptr1, ptr2, ptr3;
int res1;
int res2;
int bes1;
int bes2;
// reine Threadzeile
res1 = pthread_create(&ptr1, NULL, (void *)&funktion1,(void *)Zahl.z1);
//Fehlerabfrage Thread3
if(res1 != 0)
{
perror("Thread creation failed!");
}
int i;
for(i = 0; i<=10;i++)
{
Zahl.z1 = random() % 100; //Int Zahl 1-100 erzeugt
Zahl.z2 =(float)rand() / RAND_MAX; //Float Zahl 0-1 erteugt
printf("[TID: %li, PID: %i]int-Wert: %i float-Wert: %f \n",syscall(SYS_gettid), getpid(), Zahl.z1, Zahl.z2);
}
bes1 = pthread_join(&ptr1, NULL);
/*if (bes1 !=0)
{
perror("Thread join failed");
exit(1);
}
return 0;
}