Beispiel #1
0
int pthread_completejoin(pid_t pid, FAR void *exit_value)
{
  FAR struct task_group_s *group = task_getgroup(pid);
  FAR struct join_s *pjoin;

  sinfo("pid=%d exit_value=%p group=%p\n", pid, exit_value, group);
  DEBUGASSERT(group);

  /* First, find thread's structure in the private data set. */

  (void)pthread_takesemaphore(&group->tg_joinsem);
  pjoin = pthread_findjoininfo(group, pid);
  if (!pjoin)
    {
      serr("ERROR: Could not find join info, pid=%d\n", pid);
      (void)pthread_givesemaphore(&group->tg_joinsem);
      return ERROR;
    }
  else
    {
      bool waiters;

      /* Save the return exit value in the thread structure. */

      pjoin->terminated = true;
      pjoin->exit_value = exit_value;

      /* Notify waiters of the availability of the exit value */

      waiters = pthread_notifywaiters(pjoin);

      /* If there are no waiters and if the thread is marked as detached.
       * then discard the join information now.  Otherwise, the pthread
       * join logic will call pthread_destroyjoin() when all of the threads
       * have sampled the exit value.
       */

      if (!waiters && pjoin->detached)
        {
           pthread_destroyjoin(group, pjoin);
        }

      /* Giving the following semaphore will allow the waiters
       * to call pthread_destroyjoin.
       */

      (void)pthread_givesemaphore(&group->tg_joinsem);
    }

  return OK;
}
Beispiel #2
0
static void *findjoininfo_callback(void *param)
{
	int ret_chk = 0;
	FAR struct task_group_s *group;
	FAR struct join_s *st_pjoininfo;

	g_bpthreadcallback = true;

	pid_t pid = getpid();
	group = task_getgroup(pid);

	st_pjoininfo = pthread_findjoininfo(group, pid);
	if (st_pjoininfo == NULL) {
		printf("pthread_findjoininfo: Fail \n");
		g_bpthreadcallback = false;
		goto err;
	}
	ret_chk = pthread_equal((pid_t)st_pjoininfo->thread, pid);
	if (ret_chk != 1) {
		printf("tc_pthread_pthread_findjoininfo_destroyjoin pthread_equal fail\n");
		g_bpthreadcallback = false;
		goto err;
	}

	pthread_destroyjoin(group, st_pjoininfo);

	st_pjoininfo = pthread_findjoininfo(group, pid);
	if (st_pjoininfo != NULL) {
		printf("pthread_findjoininfo: st_pjoininfo Fail \n");
		g_bpthreadcallback = false;
		goto err;
	}
err:
	pthread_exit(NULL);
	return NULL;
}