2014년 3월 9일 일요일

pthread example

솔라리스나 Linux에서는

pthread가 종료한 후에 바로 프로세스의 cpu 사용률이 줄어드는데

HP-UX에서는 자원 사용률이 줄어들지 않네요.

pthread가 자기 동작을 하고 나서 왜 cpu사용률이 줄어들지 않는지 정말 궁금하네요.   -> DETACHED 모드일때 종료시 좀비상태로 돌입

source..

#include <stdio.h>
#include <pthread.h>
pthread_attr_t  tattr;
void *thread_comm();
int main()
{
    pthread_attr_init(&tattr);
    pthread_attr_setscope(&tattr,PTHREAD_SCOPE_SYSTEM);
    pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
    pthread_t       p_thread;
    if (pthread_create( &p_thread, &tattr, thread_comm, NULL) !=0 )
    {
        printf("thread Create error\n");
        return ( -1 );
    }
    sleep (1000);
    return 0;
}

void *thread_comm()
{
    int i,j,k,n;
    int rst;
    pthread_detach(pthread_self());
    for ( i=0; i<10000; i++)
    {
        for ( j=0; j<10000; j++)
        {
            n = i+j;
        }
    }
    printf("thread_comm end.\n");
}

댓글 없음:

댓글 쓰기