[87] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

Re: Resource exhaustion

daemon@ATHENA.MIT.EDU (Christopher Provenzano)
Wed Aug 16 18:26:49 1995

To: Greg Page <greg.page@caldera.com>
Cc: guillory@ncsa.uiuc.edu, pthreads@MIT.EDU
In-Reply-To: Your message of "Fri, 11 Aug 1995 16:16:45 MDT."
             <199508112216.QAA12816@caldera.com> 
Date: Wed, 16 Aug 1995 18:12:01 EDT
From: Christopher Provenzano  <proven@MIT.EDU>


> I ran into a similar problem on Linux.  You need to make
> sure the thread is created DETACHED.  This can be done
> in the pthread_attr_t structure used in the call to 
> pthread_create.
> 
> 
> The following is an example:
> 
> pthread_attr_t  thread_attr = {
>         SCHED_FIFO,
>         PTHREAD_DEFAULT_PRIORITY,
>         PTHREAD_CREATE_DETACHED,
>         NULL,
>         NULL,
>         NULL,
>         PTHREAD_STACK_DEFAULT
> };

Don't do this. Use the POSIX API pthread_attr_init(&thread_attr), followed by 
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED). POSIX
makes no gaurentee of what the internals of a pthread_attr_t is.

> 
> There is also an API, pthread_detach(),  to do this after the thread 
> is created.

This works too. Although if you know at creation time that you'll never join
with the thread then use the previous method. It's faster.

CAP

home help back first fref pref prev next nref lref last post