Sì, questo è possibile. In effetti, questa possibilità è uno dei motivi principali per cui esiste pthread_detach()
. Dalla documentazione POSIX per pthread_detach()
(vedi man pthread_detach
):
It has been suggested that a "detach" function is not necessary; the
detachstate thread creation attribute is sufficient, since a thread
need never be dynamically detached. However, need arises in at least
two cases:
1. In a cancellation handler for a pthread_join() it is nearly essen-
tial to have a pthread_detach() function in order to detach the
thread on which pthread_join() was waiting. Without it, it would
be necessary to have the handler do another pthread_join() to
attempt to detach the thread, which would both delay the cancella-
tion processing for an unbounded period and introduce a new call
to pthread_join(), which might itself need a cancellation handler.
A dynamic detach is nearly essential in this case.
2. In order to detach the "initial thread" (as may be desirable in
processes that set up server threads).
Così che cosa si sta proponendo va bene secondo le norme.
Edit: solo per confermare che un ulteriore, i POSIX description of exec()
stati:
Il filo iniziale nuova immagine del processo è fissato a accostabili, come se creato con l'attributo detachstate impostato PTHREAD_CREATE_JOINABLE.
Prenderesti in considerazione l'aggiunta di un link alla tua fonte per l'ultima modifica? Credo che tu abbia capito da qui: http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html, ma volevo prima confermare. Ottima risposta, però! – currysensei
@currysensei: aggiunto! – psmears