Solved

Why i should use pthread_detach?

Posted on 2006-10-25
1
1,328 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

789 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