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 7737107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:54:47+00:00 2026-06-01T07:54:47+00:00

I used to get a trouble with pthread_exit() . I know there is no

  • 0

I used to get a trouble with pthread_exit(). I know there is no way to use pthread_exit() in a way like

pthread_exit(&some_local_variable);

We always need to use pthread_exit() like:

pthread_exit("Thread Exit Message or something necessary information");

I once coded a simple program for testing purpose.
I made four thread functions for addition, subtraction, multiplication and division of two integers, respectively. Then while performing these operations on four different threads, I tried to return the result of the operation by pthread_exit(). What I mean is something like:

pthread_exit(&add_result);

When I ran the code in CentOS 6, I got the desired result (i.e., garbage values from all the threads) as pthread_exit() cannot be used like that. But, I got confused. Because for the first time, I ran that code in Ubuntu 11.10 and got three absolutely correct result(correct result of the operation) from three threads and garbage value from one thread. This confused me because why three threads are giving correct result of operation?

Moreover, I used different sleep times for those threads. I found that the thread having least sleep time gave the garbage value.

As gcc is the compiler for both these operating systems, why one system has bugs like this?
It confuses novice programmers like me. If it is not a bug, can anyone explain it to me why is this happening?

  • 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-06-01T07:54:48+00:00Added an answer on June 1, 2026 at 7:54 am

    pthread_exit just takes a pointer to a void. If you pass the address of a variable local to the thread, sometimes that memory will have been reused for something else. Sometimes it will still be there. There’s no guarantee that after a thread exits, some part of the system will go and make sure that all of the memory it was using is set to garbage values.

    It’s not a bug – the system is doing exactly what you ask it.

    Bonus related answer – Can a local variable’s memory be accessed outside its scope?

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

Sidebar

Related Questions

I'm having trouble setting up my svn. I used apt-get install subversion to install
i use java reflections to get methods used in a class.I also want to
I'm having trouble trying to get this functionality to work. I would like to
When building PHP applications I always end up having trouble trying to get everything
i used ftp-get function to download images from server. But by accident i used
Whats query can be used to get the details of Indexes of any table?
I found that PageProxy can be used to get data from page, but I
I have a fairly simple pagination query used to get rows from a table
The AVAudioRecorder in the iPhone SDK can be used to get the peak and
I'm serving a semi-static site with rails, just to get used to rails conventions.

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.