LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   how to change and pass thread parameter back to main (http://www.linuxquestions.org/questions/programming-9/how-to-change-and-pass-thread-parameter-back-to-main-364881/)

dragondad 09-19-2005 10:03 AM

how to change and pass thread parameter back to main
 
I have a question no solution yet, when we call pthread_create, we can pass the parameter to thread function, but how can we change the passed parameter, and pass it back to main().
If you know how to do it, please give me a short sample, or just a URL you think will be helpful.
Thanks.

jlliagre 09-19-2005 01:13 PM

I guess you can pass whatever you like as parameter to pthread_create, just cast it to void*, so is looks very possible to pass the address of some data allocated in your main for this thread.
Before the thread finish its job (pthread_join) it can modify the pointed data, which should be visible by your main function.

dragondad 09-19-2005 01:42 PM

Could you please give me a short sample code, since I didn't see how the parameter passed to thread can be modified and pass back to main.
Thanks.

jlliagre 09-19-2005 01:58 PM

I didn't wrote you can modify the parameter passed, I wrote you can pass as the parameter a pointer to data that is R/W from both threads.


All times are GMT -5. The time now is 01:06 PM.