[질문] 쓰레드 생성과 종료 문제

bosub의 이미지

소켓을 열어놓고, 메시지가 오면 쓰레드를 생성해서 메시지 처리를 하고 쓰레드는 죽습니다. 아래와 같은 구조가 되는데요
문제는
1. 쓰레드가 빈번하게 생성되고 죽어야 하기 때문에
pthread_t의 처리가 어렵네요. 어떻게 처리를 해야 할지

2. pthread_t를 무한대로 잡을 수가 없기 때문에
사용한 pthread_t 를 다시 사용해야 하는데
쓰레드가 종료되어 자원을 반납했는지 어떻게 알 수 있나요?
그리고 종료된 쓰레드의 pthread_t를 재 사용 할 수 있나요?

while (1)
{
select();

for (...)
{  
if (FD_SET(..))
{
    pthread_crate();
    pthread_join();         
}
}
}
mach의 이미지

Quote:
#include <pthread.h>
pthread_attr_t tattr;
pthread_t tid;
void *start_routine;
void arg
int ret;
...
/* initialized with default attributes */
ret = pthread_attr_init(&tattr);
ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
ret = pthread_create(&tid, &tattr, start_routine, arg);
...

see this simple code and advance this code...

good luck~

------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.