Solved

Why i should use pthread_detach?

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now