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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:27:25+00:00 2026-05-22T16:27:25+00:00

hello everyone I have some question about threads if for example I have some

  • 0

hello everyone I have some question about threads if for example I have some thread 1 which allocates some piece of the memory, and anohter thread (let’s assume 2) is killing thread 1 using pthread_cancel() or just using return what is going on with the peace of memory which it allocated? will be leak if thread 1 didn’t free this piece of memory? thanks in advance for any answer

edited

just to make it clearer, as I know pthread_cancel() kills thread, but what is going on with its memory when I kill it? In case of return all thread will be dead if 1 is the main thread

  • 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-22T16:27:26+00:00Added an answer on May 22, 2026 at 4:27 pm

    Yes, it will leak memory in that case. C does not have any garbage collection — if you allocate memory and fail to free it, it will be leaked, plain and simple.

    If you want to avoid leaking memory, don’t call pthread_cancel. Make your threads exit gracefully by setting a flag asking them to exit, and then when they detect that that flag is set, they can free their memory and kill themselves by returning from their thread procedures or by calling pthread_exit.

    Alternatively, you can set a thread cleanup handler by calling pthread_cleanup_push, which will get called when your thread exits or gets canceled by a call to pthread_cancel. You can use a handler function which will free any allocated memory you have outstanding.

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

Sidebar

Related Questions

hello everyone I have some problem with understanding this piece of the code: import
Hello everyone i have an question about firefox add-on: How i can get the
Hello everyone Masters Of Web Delevopment :) I have a piece of PHP script
Hello everyone I want to ask a question about including guards in C programming.
Hello everyone! I have a website which is http://www.urbanelementz.ca ... It's currently in development.
Hello good morning everyone, i have an iphone app which is still in development
Some details XAMPP 1.7.1 OS tested on vista and xp Hello everyone. I have
Hello everyone I have error which breaks up my build for no reason, here
Hello everyone I have some problem to grab movie title with regular expression. how
Hello everyone I'm trying to improve my Java skills by solving some problems from

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.