pthread_detach()does what you are looking for. It seems like this will solve your problem (no leak) with much less complexity!
That way, you can safely call pthread_detatch(_daemon)when you are done with it inside another thread, without worrying about the thread itself still working. It does not terminate the thread; instead, it causes the thread to clear when it terminates.
From the documentation:
pthread_detach() , . , pthread_detach() .
, attr :
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
. man- pthread_create() :
, . [snip] , . default, , attr ( pthread_attr_setdetachstate (3)).