|
|
pthread_create EAGAIN Resource Problem
I've inherited UNIX program written in C which uses the pthread
libraries to pthread_create for one transaction totaling 3000 transactions a
day. The problem I have is the program runs out of thread resources
indicated by the pthread_create return = EAGAIN on the 2164 transaction.
The thread procedure uses the system call to execute a program which I feel
is an overkill. The thread procedure uses pthread_exit before returning
from the thread procedure and indicates each thread is returning. With
the "ps -emo THREAD" command the number of threads shown for the daemon is
10 when the EAGAIN occurs.
Does anyone know why the daemon runs out of thread resources?
Thanks...
--
Steve
|
|
0
|
|
|
|
Reply
|
Steve
|
10/31/2003 4:14:23 AM |
|
Steve wrote:
> I've inherited UNIX program written in C which uses the pthread
> libraries to pthread_create for one transaction totaling 3000 transactions a
> day. The problem I have is the program runs out of thread resources
> indicated by the pthread_create return = EAGAIN on the 2164 transaction.
If it's always after the same number of transactions this sounds like
it may be a simple memory leak/exhaustion. To create a thread we
need to be able to allocate memory for it's stack etc. You can
get EAGAIN if the allocation fails.
Gavin
|
|
0
|
|
|
|
Reply
|
Gavin
|
10/31/2003 10:56:45 AM
|
|
Steve wrote:
>
> I've inherited UNIX program written in C which uses the pthread
> libraries to pthread_create for one transaction totaling 3000 transactions a
> day. The problem I have is the program runs out of thread resources
> indicated by the pthread_create return = EAGAIN on the 2164 transaction.
> The thread procedure uses the system call to execute a program which I feel
> is an overkill. The thread procedure uses pthread_exit before returning
> from the thread procedure and indicates each thread is returning. With
> the "ps -emo THREAD" command the number of threads shown for the daemon is
> 10 when the EAGAIN occurs.
>
> Does anyone know why the daemon runs out of thread resources?
What are the attributes of the pthread? Either you *MUST* set the
attributes to detached (see "man pthread_attr_setdetachstate") or you
*MUST* do a pthread_join after it terminates. As the Answer Book notes
>>
For nondetached (PTHREAD_CREATE_JOINABLE) threads, it is very important
that some thread join with it after it terminates--otherwise the
resources of that thread are not released for use by new threads. This
commonly results in a memory leak. So when you do not want a thread to
be joined, create it as a detached thread.
<<
John Howells
|
|
0
|
|
|
|
Reply
|
John
|
10/31/2003 3:03:23 PM
|
|
the pthread_exit function does not free the system resource !
I think you have two way for solving your problem :
first one is to do a "pthread_join" call by the main function then the
thread end. This function return the return code of the thread and free the
system resource.
the second way is to create a detached thread so the system resource is
freed on the pthread_exit. The detached thread creation look like this :
int
DaTCreateDetached(DaThread* t,DAT_RETURN StartRoutine (DAT_ARG), void * arg)
{
int result;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); /* system-wide
contention */
result=pthread_create( &t->Thread, &attr, StartRoutine, arg);
pthread_attr_destroy(&attr);
if (result==0) return TRUE;
return FALSE;
}
"Steve" <waro@bellsouth.REM.net> a �crit dans le message news:
Ijlob.2436$un.1111@bignews6.bellsouth.net...
>
> I've inherited UNIX program written in C which uses the pthread
> libraries to pthread_create for one transaction totaling 3000 transactions
a
> day. The problem I have is the program runs out of thread resources
> indicated by the pthread_create return = EAGAIN on the 2164 transaction.
> The thread procedure uses the system call to execute a program which I
feel
> is an overkill. The thread procedure uses pthread_exit before returning
> from the thread procedure and indicates each thread is returning. With
> the "ps -emo THREAD" command the number of threads shown for the daemon is
> 10 when the EAGAIN occurs.
>
> Does anyone know why the daemon runs out of thread resources?
>
> Thanks...
>
> --
> Steve
>
>
|
|
0
|
|
|
|
Reply
|
Ga
|
10/31/2003 3:15:46 PM
|
|
|
3 Replies
853 Views
(page loaded in 0.053 seconds)
|
|
|
|
|
|
|
|
|