LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2005, 10:03 AM   #1
dragondad
LQ Newbie
 
Registered: Aug 2005
Posts: 18

Rep: Reputation: 0
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.
 
Old 09-19-2005, 01:13 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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.
 
Old 09-19-2005, 01:42 PM   #3
dragondad
LQ Newbie
 
Registered: Aug 2005
Posts: 18

Original Poster
Rep: Reputation: 0
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.
 
Old 09-19-2005, 01:58 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gtk - How to pass in a parameter Ian D Programming 4 10-28-2005 11:23 AM
Main thread sending notification to child thread rajesh_b Programming 1 09-22-2004 09:15 AM
PHP Pass Parameter Gerardoj Programming 2 05-25-2004 08:12 AM
How to change function parameter value and return back to the main shell program Bassam Linux - General 1 01-26-2004 10:02 AM
send parameter from thread to thread marek Programming 2 09-08-2003 05:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration