pthread_create 호출에서 errno(12:자원부족)으로 오류가 발생하고 있습니다.

abwlts의 이미지

소켓으로 전문을 받아 쓰레드로 처리하는 프로그램이
대량의 전문을 받다가 어느 순간,
pthread_create 호출에서 errno(12:자원부족)으로 오류가 발생하고 있습니다.
쓰레드 최대값은 500으로 잡혀있어 순간적으로 전문이 폭주해 날수 있기는 하지만,
어느 순간부터는 뜸하게 들어오는 모든 전문에 대해 발생하고 있습니다.
OS는 AIX5.3입니다.

아래는 dbx를 떠본 결과입니다.

여기 저기 찾아봤지만, 딱 들어맞는 결과를 찾기는 힘드네요.

# dbx -a 1753222
Waiting to attach to process 1753222 ...
Successfully attached to pxelo1000.
warning: Directory containing pxelo1000 could not be determined.
Apply 'use' command to initialize source path.

Type 'help' for help.

stopped in _global_lock_common at 0x900000000165284 ($t210865)
0x900000000165284 (_global_lock_common+0x3b0) e8410028 ld r2,0x28(r1)
(dbx) where
_global_lock_common(??, ??, ??) at 0x900000000165284
pthread_exit(??) at 0x90000000016e2c0
Server(arg = (nil)), line 912 in "pxelo1000.c"
_pthread_body(??) at 0x90000000016643c
(dbx)

(dbx) thread
$t1 wait 0xf10006000126ea08 running 10657877 k no pro main
$t211857 runnable u no pro _usched_swtch
$t210510 wait 0x09001000a02a86b0 running 9392205 k no pro _event_notify
$t210752 wait 0x09001000a02a9460 running 3207371 k no pro _event_notify
$t210753 wait 0x00000001100126d8 blocked 9117809 k no pro _usched_dispatch_front
$t211271 wait 0x09001000a02a9840 running 3481713 k no pro _event_notify
$t211936 wait 0x09001000a02a6e40 running 6775035 k no pro pthread_exit
$t210754 wait 0x09001000a02a8580 running 10604603 k no pro _event_notify
$t211119 wait 0x09001000a02a7f70 running 5161195 k no pro _event_notify
$t211683 wait 0x00000001100126d8 blocked 6025361 k no pro _usched_dispatch_front
$t211012 wait 0x09001000a02a6e40 running 8294603 k no pro pthread_exit
$t211013 wait 0x00000001100126d8 blocked 7503965 k no pro _usched_dispatch_front
$t211618 wait 0x09001000a02a81b0 running 4501583 k
(dbx) thread
$t1 wait 0xf10006000126ea08 running 10657877 k no pro main
$t211857 runnable u no pro _usched_swtch
$t210510 wait 0x09001000a02a86b0 running 9392205 k no pro _event_notify
$t210752 wait 0x09001000a02a9460 running 3207371 k no pro _event_notify
$t210753 wait 0x00000001100126d8 blocked 9117809 k no pro _usched_dispatch_front
$t211271 wait 0x09001000a02a9840 running 3481713 k no pro _event_notify
$t211936 wait 0x09001000a02a6e40 running 6775035 k no pro pthread_exit
$t210754 wait 0x09001000a02a8580 running 10604603 k no pro _event_notify
$t211119 wait 0x09001000a02a7f70 running 5161195 k no pro _event_notify
$t211683 wait 0x00000001100126d8 blocked 6025361 k no pro _usched_dispatch_front
$t211012 wait 0x09001000a02a6e40 running 8294603 k no pro pthread_exit
$t211013 wait 0x00000001100126d8 blocked 7503965 k no pro _usched_dispatch_front
$t211618 wait 0x09001000a02a81b0 running 4501583 k no pro _event_notify
$t211464 wait 0x09001000a02a6e40 running 5972151 k no pro pthread_exit
$t211832 wait 0x09001000a02a6e40 running 7737449 k no pro pthread_exit
:

dbx에서 thread command의 결과는 $t1부터 세었을 경우 568개가 있는데 그중 일부입니다.

소스는 아래의 유형입니다.
무엇이 문제일까요?

:
:
 
int   iSockFd;
 
void *Server( void *arg );
 
/*
 *  Function Name : main
 *  Argument      : int  argc, char *argv[]
 *  Return Value  : int
 *  Description   : Main Function
 */
int main( int argc, char *argv[] )
{
    :
    :
    while( 1 )
    {
        :
        :
 
        iAcptFd = accept( iSockFd, &peeraddr_in, &iAdrLen );
 
        :
        :
 
        if( pthread_create( &stTrdBuf.ptThread[iIndexN], NULL, Server, (void *)stAllocBuf ) )
        {
            LOGPUT( _FL_, 9, 0, "Thread Create Error=[%d]", errno );
            LibFreeThreadContext( iIndexN );
            free( stAllocBuf );
            close( iAcptFd );
        }
 
    }   /* end of while() */
 
}   /*  end of main() */
 
/*
 *  Function Name : Server
 *  Argument      : void *arg( Socket Fd )
 *  Return Value  : void *
 *  Description   : Thread Create Server Function
 */
void *Server( void *arg )
{
    :
    :
 
    pthread_detach( pthread_self() ); /* Thread 분리 */
 
    :
    :
 
    close( iAcptFd ); if( sAllocBuf ) free( sAllocBuf );
 
    if( LibFreeThreadContext( iIndexN ) ) /* iIndex 번째 Thread Free */
    {
        LOGPUT( _FL_, 9, 0, "LibFreeThreadContext Error=[%d]", errno );
    }
 
    pthread_exit( (void *)NULL );
 
}   /* end of Server() */

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.