Solved

Why i should use pthread_detach?

Posted on 2006-10-25
1
1,316 Views
Last Modified: 2008-01-09
Can someone explain me the pthread_detach() function?

Why i should use it and what is the usage for it?
0
Comment
Question by:woigl
1 Comment
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
ID: 17801864
Hi woigl,

Resource taken by a thread would remain occupied until a pthread_join() returns. i.e. resources are not freed even after calling pthread_exit(). For a detached pthread, memory reousrces are freed upon thread exit and can be recycled immediately.
You would like such an arrangement in say a threaded server where you keep a pool of min no of server threads and spawn, kill them as required. It is not necessary to know if processing completed successfully (webserver) and you would not like to join every thread, nor would it be convenient to do so.

Cheers!
sunnycoder
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question