send parameter from thread to thread
As is written in this title, i would like to send data from one thread to second by the parameter of first thread. So it should looks like this:
void * my_thread1(void *my_parameter) { int statement = 1; return (void *)statement } main (..) { int local_value; pthread_create(thread_ID,..., my_thread1,....); //I wait as thread my_thread1 will be finished pthread_join(&thread_ID, (void *)&local_value); printf("That's data received from my_thread1 = %d, local_value) } This is a part of my program which i am interested a lot, could you help me?? (where is the error and what about sending data like float char and double????) |
The problem is how you are returning your value. pthread_join really wants the address of a pointer. Allocate the memory in your thread function, then return the address of that memory. Here's a similar example that works:
Code:
#include <stdio.h> Code:
gcc -Wall -o testthread testthread.c -lpthread |
So your program works perfectly (but i used little different statement in thread fuction ThreadFunction ->
return *statement instead return(statement) What about my program it also work great but i forgot to delete one line pthread_exit which i had in my thread function :D (God punish us for stupidity), without this line it works like it should, sending data from one thread to second Thanks eric for help |
All times are GMT -5. The time now is 12:50 AM. |