pthread and shared variables
I am trying to share a character array as shared data container between a pthread and the main program. Not really that experienced in C programming so not able to find out what is wrong with what I have done. Anyone able to have a quick look?
Bacically what I do is the following:
1) define the variable at the start of my main code:
2) start the thread with:
3) which calls:
pthread_create(&threads, NULL, run_thread, 0);
4) and then the thread sets the DATA as below:
void *run_thread(void *threadid)
5) Finally I wait for the thread in the main code and get the value as below:
void runThread(int *ready,char *data)
Now what happens with the above is that the value for DATA is NULL everytime. I have checked that is gets set in the thread, but somehow it does not carry over to the main code. A bit like the variable in the thread is a copy of the original variable.
Probably some C principle that I don't quite understand, so if someone would take a minute and point out that would be great :)
Thanks for your help in advance,