Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    19

    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.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,879
    I'm not all that familiar with pthreads, but I believe they're not in their own address space, so cant you just send a pointer or a pointer to a pointer as the parameter and have the thread update it?
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401
    Quote Originally Posted by Roxoff
    I'm not all that familiar with pthreads, but I believe they're not in their own address space, so cant you just send a pointer or a pointer to a pointer as the parameter and have the thread update it?
    This is right. But take care about race conditions!!! The two threads (main() and the routine passed to pthread_create) runs in "parallel", so when accessing to the same variable once could not see variable modifications as expected...
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •