Есть код функции pthread_join из glibc.
Подскажите, пожалуйста:
1) Номер строки и что происходит, если для потока уже вызвали pthread_join?
#include <errno.h>
#include <stdlib.h>
#include <atomic.h>
#include "pthreadP.h"
#include <stap-probe.h>
static void
cleanup (void *arg)
{
(void) atomic_compare_and_exchange_bool_acq ((struct pthread **) arg, NULL,
THREAD_SELF);
}
int
pthread_join (pthread_t threadid, void **thread_return)
{
struct pthread *pd = (struct pthread *) threadid;
if (INVALID_NOT_TERMINATED_TD_P (pd))
return ESRCH;
if (IS_DETACHED (pd))
return EINVAL;
struct pthread *self = THREAD_SELF;
int result = 0;
LIBC_PROBE (pthread_join, 1, threadid);
pthread_cleanup_push (cleanup, &pd->joinid);
int oldtype = CANCEL_ASYNC ();
if ((pd == self
|| (self->joinid == pd && (pd->cancelhandling & (CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK | TERMINATED_BITMASK)) == 0))
&& !CANCEL_ENABLED_AND_CANCELED (self->cancelhandling))
result = EDEADLK;
else if (__builtin_expect (atomic_compare_and_exchange_bool_acq (&pd->joinid, self,NULL), 0))
result = EINVAL;
else
lll_wait_tid (pd->tid);
CANCEL_RESET (oldtype);
pthread_cleanup_pop (0);
if (__glibc_likely (result == 0))
{
pd->tid = -1;
if (thread_return != NULL)
*thread_return = pd->result;
__free_tcb (pd);
}
LIBC_PROBE (pthread_join_ret, 3, threadid, result, pd->result);
return result;
}