Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6124093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:05:36+00:00 2026-05-23T16:05:36+00:00

Note: I have removed all required error checking in the following snippet. … void

  • 0

Note: I have removed all required error checking in the following snippet.

...
void *thread_function(void *arg)
{
   ...
   pthread_exit("Hello");
}

pthread_t a_thread;
void *thread_result;

pthread_create(&a_thread, NULL, thread_function, NULL);
pthread_join(a_thread, &thread_result);
/*

int pthread_join(pthread_t th, void **thread_return);
The second argument is a pointer to a pointer that itself points to the return
value from the thread.

int pthread_exit(void *retval);
This function terminates the calling thread, returning a pointer to an object which
cannot be a local variable.

*/

Question: how does pthread_join populate the variable of thread_result?
Since the variable thread_result has no allocated space to hold information,
if pthread_join allocates space for thread_result, then major thread must
deallocate the resource holding by the varable. As you can see, the code doesn’t
include the deallocation resource of thread_result. So I assume that pthread_join
in fact doesn’t allocate space for thread_result.

Now the new question is how the variable thread_result can contain information without
being allocated any space?

//Update-1: Add the definition of pthread_exit.

//Update-2: Add the definition of thread_function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:05:37+00:00Added an answer on May 23, 2026 at 4:05 pm

    Your conclusion is correct: pthread_join doesn’t allocate memory for the result.

    In fact, what happens is quite simple:

    • pthread_exit is provided a (void*) pointer to the result by the thread itself; it’s up to the thread to decide where this pointer comes from.
    • Subsequently, pthread_join — called from another thread — stores that pointer in the variable pointed to by its second argument.

    As far as the result is concerned, all that pthreads is doing is passing a pointer across thread boundaries. It is up to the application to ensure that the pointed-to memory is deallocated in a manner that’s consistent with how it’s been allocated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML (note the CSS making the background black and text
Note - I have not delved very deeply into Apple's iPhone SDK yet. However,
NOTE: I have solved the majority of this problem but have run into a
Note: I have given up on compiling iPhone Apps without a developer certificate for
Note I have completely re-written my original post to better explain the issue I
(Please note that I have seen a similar question on StackOverflow recently, however I
I have to give a general note to some huge Java project for which
Note that this function does not have a { and } body. Just a
Note: I am just consuming webservice I have no control over webservice code. So
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.