LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-28-2012, 02:12 AM   #1
sandeep_nandal
LQ Newbie
 
Registered: Feb 2012
Posts: 2

Rep: Reputation: Disabled
POSIX Threads : Implementation of pthread_exit(void *)


Hi there,
I hve started learning about pthreads and their implementations. I'm wondered as we use pthread_join() to collect the return value or pthread_exit() of the thread function. Therefore, In which form the whole procedure work to collect n return the exit value.

I studied that we can use static variables or malloc function to create a string and return that to the calling function. Then in malloc case it's the caller's responsibilty to free that memory.

So, the question is in threads as we collect the return value as void *, so do we need to free that memory after the use ourselves or else what kind of mechanism is used in this whole procedure.

Thank you.
 
Old 02-28-2012, 08:45 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
The same principle holds true when you are using threads: if memory is allocated it must be freed.

You must be very careful when handling dynamically allocated memory in a multi-thread situation.
 
Old 02-28-2012, 11:41 PM   #3
sandeep_nandal
LQ Newbie
 
Registered: Feb 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
@sundialsvcs, thanks for your reply, I want to know, how the memory of the return string is allocated by pthread_exit() which we can use in our main. Through static character array which automatically taken care for being freed or through malloc or calloc() which we have to free ourselves. Or some othr mechanism?
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Proper implementation of POSIX threads nrhoades Programming 2 04-06-2011 02:35 PM
POSIX Threads embesil Programming 4 03-07-2009 01:03 PM
Implementation of POSIX mqueues in Linux 2.6 greg fe Linux - Kernel 1 08-11-2007 04:15 AM
POSIX Threads mannahazarika Programming 4 07-16-2006 11:00 PM
About POSIX threads Ephracis Programming 1 12-03-2004 06:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:01 AM.

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