0
#include <pthread.h>
static void * worker_thread(void *);
void some_func(void)
{
pthread_t * tmp;
tmp = malloc(sizeof(pthread_t));
if (NULL != tmp)
{
if (!pthread_create(tmp, NULL, worker_thread, (void *)tmp))
pthread_detach(*tmp);
else
free(tmp);
}
}
static void * worker_thread(void * p)
{
/* do work */
free(p);
return(NULL);
}
나는 귀하의 공격적인 공격을 찾습니다. – Randolpho
경쟁 조건이 있습니다. 실제로 스레드를 분리하기 전에 tmp를 해제 할 수 있습니다. 스택 변수를 사용하지 않는 이유는 무엇입니까? –
주의하십시오. 어쨌든 –