Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #1410
| From | andrew@cucumber.demon.co.uk (Andrew Gabriel) |
|---|---|
| Newsgroups | comp.programming.threads |
| Subject | Re: Are detached threads useful? |
| Date | 2013-03-02 15:16 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <kgt546$s4b$1@dont-email.me> (permalink) |
| References | <cfd2e5c1-5c00-4ebb-9da1-a3588dc41d79@w14g2000vba.googlegroups.com> |
In article <cfd2e5c1-5c00-4ebb-9da1-a3588dc41d79@w14g2000vba.googlegroups.com>,
Michael Podolsky <michael.podolsky.69@gmail.com> writes:
> Hello All,
>
> I have a general feeling that to detach a thread is a bad idea.
>
> Detaching threads allows us not to register some threads in some
> containers, but that operation should be very cheep. It saves us from
> long waiting on join operation... but implementing effective join
> operations on a number of threads is anyway an essential task
>
> We pay for using detached threads by producing shaky designs (what was
> ok to terminate today may be not ok tomorrow when we change some
> thread functionality).
>
> In short, I declare "detached threads should not be used". And I would
> like to hear about examples where having them is really a good (or
> even necessary?) idea.
>
> Thank you,
> Michael
Looking through source I've written for various things, these
are the two cases where I've used pthread_detach() (each several
times in different programs)...
1)
A thread which is about to exit, and no other thread in the
process cares or needs to know, so the sequence is:
pthread_detach(pthread_self());
pthread_exit(NULL);
This is to avoid leaving a detached/zombie thread around which
will never be reaped - just a matter of tidyness really, although
it could become important if a process does this repeatedly that
it isn't leaking zombie threadids (none of mine do it frequently).
2)
A thread which performs only a monitoring/reporting function
for the process, which simply continues to run until all the
non-detached threads finish and exit.
Both of these can be done in other ways without using pthread_detach,
but it's a question if the additional complexity is justified.
Did you have specific uses of pthread_detach in mind which you
regard as wrong?
--
Andrew Gabriel
[email address is not usable -- followup in the newsgroup]
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar
Are detached threads useful? Michael Podolsky <michael.podolsky.69@gmail.com> - 2013-02-14 18:52 -0800
Re: Are detached threads useful? Marcel Müller <news.5.maazl@spamgourmet.org> - 2013-02-16 11:00 +0100
Re: Are detached threads useful? andrew@cucumber.demon.co.uk (Andrew Gabriel) - 2013-03-02 15:16 +0000
Re: Are detached threads useful? Michael Podolsky <michael.podolsky.69@gmail.com> - 2013-03-07 22:27 -0800
Re: Are detached threads useful? andrew@cucumber.demon.co.uk (Andrew Gabriel) - 2013-03-18 14:57 +0000
Re: Are detached threads useful? Gerald Breuer <Gerald.Breuer@googlemail.com> - 2013-03-08 19:11 +0100
csiph-web