Ejemplo n.º 1
0
static inline void
s_destroy_all(void) {
  if (is_child == true) {

    s_stop_all();

    (void)lagopus_mutex_lock(&stop_lock);
    {
      size_t i;
      test_thread_t tt;

      /*
       * Wait the threads done and delete it.
       */
      if (tts != NULL) {
        for (i = 0; i < n_created_thds; i++) {
          tt = &(tts[i]);
          (void)lagopus_thread_wait((lagopus_thread_t *)&tt, -1LL);
          (void)lagopus_thread_destroy((lagopus_thread_t *)&tt);
        }
        free((void *)tts);
        tts = NULL;
      }

      if (polls != NULL) {
        for (i = 0; i < n_created_polls; i++) {
          lagopus_qmuxer_poll_destroy(&(polls[i]));
        }
        free((void *)polls);
        polls = NULL;
      }

      if (bbqs != NULL) {
        for (i = 0; i < n_created_bbqs; i++) {
          lagopus_bbq_destroy(&(bbqs[i]), true);
        }
        free((void *)bbqs);
        bbqs = NULL;
      }

      if (qmx != NULL) {
        lagopus_qmuxer_destroy(&qmx);
        qmx = NULL;
      }

      if (start_lock != NULL) {
        lagopus_mutex_destroy(&start_lock);
        start_lock = NULL;
      }
    }
    (void)lagopus_mutex_unlock(&stop_lock);

    if (stop_lock != NULL) {
      lagopus_mutex_destroy(&stop_lock);
      stop_lock = NULL;
    }
  }
}
Ejemplo n.º 2
0
void
test_thread_create_params(void) {
  lagopus_thread_t m_thread = NULL;
  TEST_ASSERT_EQUAL_MESSAGE(
    LAGOPUS_RESULT_INVALID_ARGS,
    lagopus_thread_create(NULL, main_proc, finalize_proc,
                          freeup_proc, "m_thread", NULL),
    "thread is null");
  lagopus_thread_destroy(&m_thread);

  m_thread = NULL;
  TEST_ASSERT_EQUAL_MESSAGE(
    LAGOPUS_RESULT_INVALID_ARGS,
    lagopus_thread_create(&m_thread, NULL, finalize_proc,
                          freeup_proc, "m_thread", NULL),
    "main_proc is null");
  lagopus_thread_destroy(&m_thread);

  m_thread = NULL;
  TEST_ASSERT_EQUAL_MESSAGE(
    LAGOPUS_RESULT_OK,
    lagopus_thread_create(&m_thread, main_proc, NULL,
                          freeup_proc, "m_thread", NULL),
    "finalize_proc is null");
  lagopus_thread_destroy(&m_thread);

  m_thread = NULL;
  TEST_ASSERT_EQUAL_MESSAGE(
    LAGOPUS_RESULT_OK,
    lagopus_thread_create(&m_thread, main_proc, finalize_proc,
                          NULL, "m_thread", NULL),
    "freeup_proc is null");
  lagopus_thread_destroy(&m_thread);

  m_thread = NULL;
  TEST_ASSERT_EQUAL_MESSAGE(
    LAGOPUS_RESULT_OK,
    lagopus_thread_create(&m_thread, main_proc, finalize_proc,
                          freeup_proc, NULL, NULL),
    "thread_name is null");
  lagopus_thread_destroy(&m_thread);
}
Ejemplo n.º 3
0
static void
dummy_module_finalize(void) {
  lagopus_msg_debug(5, "called.\n");

  if (s_thd != NULL) {

    s_lock();
    {
      lagopus_thread_destroy(&s_thd);
    }
    s_unlock();

  }
}
Ejemplo n.º 4
0
void
dp_thread_finalize(lagopus_thread_t *threadptr) {
  bool is_valid = false, is_canceled = false;
  lagopus_result_t ret;

  ret = lagopus_thread_is_valid(threadptr, &is_valid);
  if (ret != LAGOPUS_RESULT_OK || is_valid == false) {
    lagopus_perror(ret);
    return;
  }
  ret = lagopus_thread_is_canceled(threadptr, &is_canceled);
  if (ret == LAGOPUS_RESULT_OK && is_canceled == false) {
    global_state_cancel_janitor();
  }
  lagopus_thread_destroy(threadptr);

  return;
}
Ejemplo n.º 5
0
int
main(int argc, const char *const argv[]) {
  int ret = 1;
  lagopus_result_t r;
  null_thread_t nt;
  size_t i;
  a_obj_t o;

  (void)argc;
  (void)argv;

  o = a_obj_create();
  if (o == NULL) {
    goto done;
  }

  for (i = 0; i < NTHDS; i++) {
    nt = &s_thds[i];
    if ((r = s_create(&nt, o)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(r);
      goto done;
    }
  }

  for (i = 0; i < NTHDS; i++) {
    nt = &s_thds[i];
    if ((r = lagopus_thread_start((lagopus_thread_t *)&nt, false)) !=
        LAGOPUS_RESULT_OK) {
      lagopus_perror(r);
      goto done;
    }
  }

  sleep(1);

  /*
   * Cancel all the thread.
   */
  for (i = 0; i < NTHDS; i++) {
    nt = &s_thds[i];
    if ((r = lagopus_thread_cancel((lagopus_thread_t *)&nt)) !=
        LAGOPUS_RESULT_OK) {
      lagopus_perror(r);
      goto done;
    }
  }

  /*
   * Destroy all the thread. If any deadlocks occur, we failed.
   */
  for (i = 0; i < NTHDS; i++) {
    nt = &s_thds[i];
    lagopus_thread_destroy((lagopus_thread_t *)&nt);
  }

  /*
   * And destroy a_obj. If a deadlock occurs, we failed.
   */
  a_obj_destroy(o);

  ret = 0;

done:
  return ret;
}
Ejemplo n.º 6
0
void
test_thread_param_destroy(void) {
  lagopus_thread_t m_thread = NULL;
  lagopus_thread_destroy(NULL);
  lagopus_thread_destroy(&m_thread);
}
Ejemplo n.º 7
0
static inline void
s_check_destroy(lagopus_thread_t *thd_ptr) {
  lagopus_thread_destroy(thd_ptr);
}
Ejemplo n.º 8
0
int
main(int argc, char const *const argv[]) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  int i;
  int n = 10000;
  lagopus_thread_t thread = NULL;
  pthread_t tid = LAGOPUS_INVALID_THREAD;

  lagopus_log_set_debug_level(10);

  if (argc > 1) {
    int tmp;
    if (lagopus_str_parse_int32(argv[1], &tmp) == LAGOPUS_RESULT_OK &&
        tmp > 0) {
      n = tmp;
    }
  }

  /* create, start, wait, destroy */
  for (i = 0; i < n; i++) {
    thread = NULL;

    if ((ret = lagopus_thread_create(
                 (lagopus_thread_t *)&thread,
                 (lagopus_thread_main_proc_t)s_main_proc,
                 (lagopus_thread_finalize_proc_t)s_finalize_proc,
                 (lagopus_thread_freeup_proc_t)s_freeup_proc,
                 (const char *) "thread",
                 (void *) NULL)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_exit_fatal("Can't create a thread.\n");
    } else {
      fprintf(stderr, "create a thread [%d]\n", i);
      if ((ret = lagopus_thread_get_pthread_id(&thread, &tid))
          != LAGOPUS_RESULT_NOT_STARTED) {
        lagopus_perror(ret);
        goto done;
      }
    }

    if ((ret = lagopus_thread_start(&thread, false)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_exit_fatal("Can't start the thread.\n");
    } else {
      ret = lagopus_thread_get_pthread_id(&thread, &tid);
      if (ret == LAGOPUS_RESULT_OK ||
          ret == LAGOPUS_RESULT_ALREADY_HALTED) {
        fprintf(stderr, " start thread:  %lu\n", tid);
      } else {
        lagopus_perror(ret);
        goto done;
      }
    }

    s_check_cancelled(&thread, false);

    if ((ret = lagopus_thread_wait(&thread, 1000LL * 1000LL * 1000LL)) !=
        LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_msg_error("Can't wait the thread.\n");
    } else {
      if ((ret = lagopus_thread_get_pthread_id(&thread, &tid))
          == LAGOPUS_RESULT_OK) {
        lagopus_msg_error(
          "Thread has been completed, but I can get thread ID, %lu\n",
          tid);
      } else if (ret != LAGOPUS_RESULT_ALREADY_HALTED) {
        lagopus_perror(ret);
        goto done;
      }
    }

    s_check_cancelled(&thread, false);

    lagopus_thread_destroy(&thread);
    fprintf(stderr, "destroy the thread [%d]\n", i);

    fprintf(stderr, "\n");
  }

  /* create, start, cancel, destroy */
  for (i = 0; i < n; i++) {
    thread = NULL;

    if ((ret = lagopus_thread_create(
                 (lagopus_thread_t *)&thread,
                 (lagopus_thread_main_proc_t)s_main_proc_with_sleep,
                 (lagopus_thread_finalize_proc_t)s_finalize_proc,
                 (lagopus_thread_freeup_proc_t)s_freeup_proc,
                 (const char *) "thread",
                 (void *) NULL)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_exit_fatal("Can't create a thread.\n");
    } else {
      fprintf(stderr, "create a thread [%d]\n", i);

      if ((ret = lagopus_thread_get_pthread_id(&thread, &tid))
          != LAGOPUS_RESULT_NOT_STARTED) {
        lagopus_perror(ret);
        goto done;
      }
    }

    if ((ret = lagopus_thread_start(&thread, false)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_exit_fatal("Can't start the thread.\n");
    } else {
      ret = lagopus_thread_get_pthread_id(&thread, &tid);
      if (ret == LAGOPUS_RESULT_OK ||
          ret == LAGOPUS_RESULT_ALREADY_HALTED) {
        fprintf(stderr, " start thread:  %lu\n", tid);
      } else {
        lagopus_perror(ret);
        goto done;
      }
    }

    s_check_cancelled(&thread, false);

    if ((ret = lagopus_thread_cancel(&thread)) !=
        LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_msg_error("Can't cancel the thread.\n");
    } else {
      if ((ret = lagopus_thread_get_pthread_id(&thread, &tid))
          == LAGOPUS_RESULT_OK) {
        lagopus_msg_error(
          "Thread has been canceled, but I can get thread ID, %lu\n",
          tid);
      } else if (ret != LAGOPUS_RESULT_NOT_STARTED &&
                 ret != LAGOPUS_RESULT_ALREADY_HALTED) {
        lagopus_perror(ret);
        goto done;
      }
    }

    s_check_cancelled(&thread, true);

    lagopus_thread_destroy(&thread);
    fprintf(stderr, "destroy the thread [%d]\n", i);

    fprintf(stderr, "\n");
  }

  /* create, start, destroy */
  for (i = 0; i < n; i++) {
    thread = NULL;

    if ((ret = lagopus_thread_create(
                 (lagopus_thread_t *)&thread,
                 (lagopus_thread_main_proc_t)s_main_proc_with_sleep,
                 (lagopus_thread_finalize_proc_t)s_finalize_proc,
                 (lagopus_thread_freeup_proc_t)s_freeup_proc,
                 (const char *) "thread",
                 (void *) NULL)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_exit_fatal("Can't create a thread.\n");
    } else {
      fprintf(stderr, "create a thread [%d]\n", i);

      if ((ret = lagopus_thread_get_pthread_id(&thread, &tid))
          != LAGOPUS_RESULT_NOT_STARTED) {
        lagopus_perror(ret);
        goto done;
      }
    }

    if ((ret = lagopus_thread_start(&thread, false)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(ret);
      lagopus_exit_fatal("Can't start the thread.\n");
    } else {
      ret = lagopus_thread_get_pthread_id(&thread, &tid);
      if (ret == LAGOPUS_RESULT_OK ||
          ret == LAGOPUS_RESULT_ALREADY_HALTED) {
        fprintf(stderr, " start thread:  %lu\n", tid);
      } else {
        lagopus_perror(ret);
        goto done;
      }
    }

    lagopus_thread_destroy(&thread);
    fprintf(stderr, "destroy the thread [%d]\n", i);

    fprintf(stderr, "\n");
  }

done:
  return (ret == LAGOPUS_RESULT_OK) ? 0 : 1;
}
Ejemplo n.º 9
0
static int
do_run(size_t nthds, ssize_t nputs) {
  int ret = 1;

  lagopus_result_t r;

  size_t i;
  size_t j;
  char thdname[16];

  lagopus_mutex_t start_lock = NULL;
  test_thread_record *tts = NULL;
  size_t n_created_thds = 0;
  lagopus_bbq_t *bbqs = NULL;
  size_t n_created_bbqs = 0;
  lagopus_qmuxer_poll_t *polls = NULL;
  size_t n_created_polls = 0;
  lagopus_qmuxer_t qmx = NULL;

  size_t n_need_watch = 0;
  size_t n_valid_polls = 0;
  ssize_t qsz;

  test_thread_t tt;
  lagopus_bbq_t bbq;

  lagopus_chrono_t put_date;

  lagopus_chrono_t t_begin;
  lagopus_chrono_t t_end;

  lagopus_chrono_t p_begin;
  lagopus_chrono_t p_t;

  ssize_t n_gets = 0;
  lagopus_chrono_t p_min = LLONG_MAX;
  lagopus_chrono_t p_max = LLONG_MIN;
  double p_sum = 0.0;
  double p_sum2 = 0.0;

  double p_avg;
  double p_sd;

  lagopus_chrono_t t_total = 0;
  double t_avg;

  if ((r = lagopus_mutex_create(&start_lock)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    goto done;
  }

  /*
   * Create the qmuxer.
   */
  if ((r = lagopus_qmuxer_create(&qmx)) != LAGOPUS_RESULT_OK) {
    lagopus_perror(r);
    goto done;
  }

  /*
   * Then create queues.
   */
  bbqs = (lagopus_bbq_t *)malloc(sizeof(lagopus_bbq_t) * nthds);
  if (bbqs == NULL) {
    goto done;
  }
  for (i = 0; i < nthds; i++) {
    if ((r = lagopus_bbq_create(&(bbqs[i]), lagopus_chrono_t,
                                1000LL * 1000LL,
                                NULL)) != LAGOPUS_RESULT_OK) {
      lagopus_perror(r);
      goto done;
    }
    n_created_bbqs++;
  }
  if (n_created_bbqs == 0) {
    goto done;
  }

  /*
   * Then create poll objects for the each queue.
   */
  polls = (lagopus_qmuxer_poll_t *)malloc(sizeof(lagopus_qmuxer_poll_t) *
                                          n_created_bbqs);
  if (polls == NULL) {
    goto done;
  }
  for (i = 0; i < n_created_bbqs; i++) {
    if ((r = lagopus_qmuxer_poll_create(&(polls[i]),
                                        bbqs[i],
                                        LAGOPUS_QMUXER_POLL_READABLE)) !=
        LAGOPUS_RESULT_OK) {
      lagopus_perror(r);
      goto done;
    }
    n_created_polls++;
  }
  if (n_created_polls == 0) {
    goto done;
  }

  /*
   * Then create threads for the each poll objects/queues.
   */
  tts = (test_thread_record *)malloc(sizeof(test_thread_record) *
                                     n_created_polls);
  if (tts == NULL) {
    goto done;
  }
  for (i = 0; i < n_created_polls; i++) {
    snprintf(thdname, sizeof(thdname), "putter " PFSZS(4, u), i);
    tt = &(tts[i]);
    if (test_thread_create(&tt, start_lock, bbqs[i], nputs,
                           (const char *)thdname) != true) {
      goto done;
    }
    n_created_thds++;
  }
  if (n_created_thds == 0) {
    goto done;
  }

  /*
   * Let the initiation begin.
   */

  /*
   * Ready, note that all the created threads do this lock.
   */
  (void)lagopus_mutex_lock(&start_lock);

  /*
   * Steady,
   */
  for (i = 0; i < n_created_thds; i++) {
    tt = &(tts[i]);
    if (lagopus_thread_start((lagopus_thread_t *)&tt, false) !=
        LAGOPUS_RESULT_OK) {
      (void)lagopus_mutex_unlock(&start_lock);
      goto done;
    }
  }

  fprintf(stdout, "Test for " PFSZ(u) " threads " PFSZ(u)
          " events/thdread start.\n", n_created_thds, (size_t)nputs);

  /*
   * Go.
   */
  (void)lagopus_mutex_unlock(&start_lock);

  WHAT_TIME_IS_IT_NOW_IN_NSEC(t_begin);

  while (true) {
    /*
     * Like the select(2)/poll(2), initialize poll objects before
     * checking events.
     */
    n_need_watch = 0;
    n_valid_polls = 0;
    for (i = 0; i < n_created_thds; i++) {
      /*
       * Check if the poll has a valid queue.
       */
      bbq = NULL;
      if ((r = lagopus_qmuxer_poll_get_queue(&(polls[i]), &bbq)) !=
          LAGOPUS_RESULT_OK) {
        lagopus_perror(r);
        break;
      }
      if (bbq != NULL) {
        n_valid_polls++;
      }

      /*
       * Reset the poll status.
       */
      if ((r = lagopus_qmuxer_poll_reset(&(polls[i]))) != LAGOPUS_RESULT_OK) {
        lagopus_perror(r);
        break;
      }
      n_need_watch++;
    }

    /*
     * If there are no valid queues, exit.
     */
    if (n_valid_polls == 0) {
      break;
    }

    /*
     * Wait for an event.
     *
     *  Note that we better set timeout, not waiting forever.
     */
    r = lagopus_qmuxer_poll(&qmx, (lagopus_qmuxer_poll_t *const)polls,
                            n_need_watch,
                            100LL * 1000LL * 1000LL);

    if (r > 0) {
      /*
       * Check which poll got an event. Actually, check all the queues
       * in this sample.
       */
      WHAT_TIME_IS_IT_NOW_IN_NSEC(p_begin);

      for (i = 0; i < n_created_thds; i++) {

        if ((qsz = lagopus_bbq_size(&(bbqs[i]))) > 0) {

          //qsz = (qsz <= 10000LL) ? qsz : 10000LL;

          lagopus_msg_debug(1, "Got " PFSZS(8, u) " events from the Q"
                            PFSZS(03, u) ".\n",
                            (size_t)qsz, (size_t)i);

          for (j = 0; j < (size_t)qsz; j++) {
            if ((r = lagopus_bbq_get(&(bbqs[i]), &put_date,
                                     lagopus_chrono_t, -1LL)) ==
                LAGOPUS_RESULT_OK) {
              /*
               * In this sample, -1LL is kinda 'EOF'. Check if we got
               * the EOF.
               */
              if (put_date == -1LL) {
                /*
                 * The queue is kinda 'closed'. From now on we don't
                 * check this queue anymore. To specify this:
                 */
                lagopus_msg_debug(1, "Got an EOF from the Q" PFSZS(04, u)
                                  ".\n", i);
                goto nullify;
              }

              p_t = p_begin - put_date;

              if (p_t < p_min) {
                p_min = p_t;
              }
              if (p_t > p_max) {
                p_max = p_t;
              }
              p_sum += (double)p_t;
              p_sum2 += ((double)p_t * (double)p_t);
              n_gets++;

            } else {
              /*
               * Something wrong for the queue. But we must not exit
               * here. Keep on checking other queues. In order to do
               * this, set NULL as the queue into the poll object for
               * the queue.
               */
              lagopus_perror(r);
            nullify:
              if ((r = lagopus_qmuxer_poll_set_queue(&(polls[i]), NULL)) !=
                  LAGOPUS_RESULT_OK) {
                /*
                 * There is nothing we can do now.
                 */
                lagopus_perror(r);
                goto done;
              }
            }
          }

        }

      }

    } else if (r == LAGOPUS_RESULT_TIMEDOUT) {
      lagopus_msg_debug(1, "Timedout. continue.\n");
      continue;
    } else {
      lagopus_perror(r);
      lagopus_msg_debug(1, "Break the loop due to error(s).\n");
      goto done;
    }
  }

  WHAT_TIME_IS_IT_NOW_IN_NSEC(t_end);

  fprintf(stdout, "Done.\n");

  fprintf(stdout, "Total # of the events:\t" PFSZS(22, u) "\n\n", n_gets);

  p_avg = p_sum / (double)n_gets;
  p_sd = (p_sum2 -
          2.0 * p_avg * p_sum +
          p_avg * p_avg * (double)n_gets) / (double)(n_gets - 1);
  p_sd = sqrt(p_sd);

  fprintf(stdout, "Queue stats:\n");
  fprintf(stdout, "wait time min =\t" PFSZS(22, d) " nsec.\n", p_min);
  fprintf(stdout, "wait time max =\t" PFSZS(22, d) " nsec.\n", p_max);
  fprintf(stdout, "wait time avg =\t%25.2f nsec.\n", p_avg);
  fprintf(stdout, "wait time sd =\t%25.2f.\n\n", p_sd);

  t_total = t_end - t_begin;
  t_avg = (double)t_total / (double)n_gets;

  fprintf(stdout, "Throughput:\n");
  fprintf(stdout, "total time:\t" PFSZS(22, d) " msec.\n",
          (size_t)(t_total / 1000LL / 1000LL));
  fprintf(stdout, "total avg:\t%25.2f nsec/event.\n", t_avg);

  ret = 0;

done:
  if (bbqs != NULL) {
    for (i = 0; i < n_created_bbqs; i++) {
      lagopus_bbq_destroy(&(bbqs[i]), true);
    }
    free((void *)bbqs);
  }

  if (polls != NULL) {
    for (i = 0; i < n_created_polls; i++) {
      lagopus_qmuxer_poll_destroy(&(polls[i]));
    }
    free((void *)polls);
  }

  if (tts != NULL) {
    for (i = 0; i < n_created_thds; i++) {
      tt = &(tts[i]);
      lagopus_thread_destroy((lagopus_thread_t *)&tt);
    }
    free((void *)tts);
  }

  if (qmx != NULL) {
    lagopus_qmuxer_destroy(&qmx);
  }

  if (start_lock != NULL) {
    lagopus_mutex_destroy(&start_lock);
  }

  return ret;
}
Ejemplo n.º 10
0
int
main(int argc, const char *const argv[]) {
  test_thread_record ttr;
  test_thread_t tt;
  bool is_canceled;
  int ret = 1;

  (void)argc;
  (void)argv;

  fprintf(stderr, "Pthread wrapper check: start\n\n");

  /*
   * Heap object
   */
  fprintf(stderr, "Heap object, regular: start\n");
  tt = NULL;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't create a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, false) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_chrono_nanosleep(5LL * 1000LL * 1000LL * 1000LL, NULL);
  test_thread_request_stop(tt);
  if (lagopus_thread_wait((lagopus_thread_t *)&tt, -1) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't wait the thread.\n");
  }
  lagopus_thread_destroy((lagopus_thread_t *)&tt);
  fprintf(stderr, "Heap object, regular: end\n\n");

  /*
   * Stack object
   */
  fprintf(stderr, "Stack object, regular: start\n");
  tt = &ttr;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't initialize a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, false) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_chrono_nanosleep(5LL * 1000LL * 1000LL * 1000LL, NULL);
  test_thread_request_stop(tt);
  if (lagopus_thread_wait((lagopus_thread_t *)&tt, -1) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't wait the thread.\n");
  }
  lagopus_thread_destroy((lagopus_thread_t *)&tt);
  fprintf(stderr, "Stack object, regular: end\n\n");

  /*
   * Cancel
   */
  fprintf(stderr, "Stack object, cancel: start\n");
  tt = &ttr;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't initialize a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, false) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_chrono_nanosleep(5LL * 1000LL * 1000LL * 1000LL, NULL);
  if (lagopus_thread_cancel((lagopus_thread_t *)&tt) != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't cancel the thread.\n");
  }
  if (lagopus_thread_wait((lagopus_thread_t *)&tt, -1) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't wait the thread.\n");
  }
  if (lagopus_thread_is_canceled((lagopus_thread_t *)&tt, &is_canceled) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("The returned value must be \"canceled\".\n");
  }
  lagopus_thread_destroy((lagopus_thread_t *)&tt);
  fprintf(stderr, "Stack object, cancel: end\n\n");

  /*
   * Heap object auto deletion
   */
  fprintf(stderr, "Heap object, auto deletion: start\n");
  s_is_deleted = false;
  tt = NULL;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't initialize a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, true) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_chrono_nanosleep(5LL * 1000LL * 1000LL * 1000LL, NULL);
  test_thread_request_stop(tt);
  lagopus_chrono_nanosleep(2LL * 1000LL * 1000LL * 1000LL, NULL);
  if (s_is_deleted == false) {
    lagopus_exit_fatal("The thread object must be freed and "
                       "the flag must be true.\n");
  }
  fprintf(stderr, "Heap object, auto deletion: end\n\n");

  /*
   * Stack object auto deletion
   */
  fprintf(stderr, "Stack object, auto deletion: start\n");
  s_is_deleted = false;
  tt = &ttr;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't initialize a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, true) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_chrono_nanosleep(5LL * 1000LL * 1000LL * 1000LL, NULL);
  test_thread_request_stop(tt);
  lagopus_chrono_nanosleep(2LL * 1000LL * 1000LL * 1000LL, NULL);
  if (s_is_deleted == false) {
    lagopus_exit_fatal("The thread object must be freed and "
                       "the flag must be true.\n");
  }
  fprintf(stderr, "Stack object, auto deletion: end\n\n");

  /*
   * Heap object cancel, auto deletion
   */
  fprintf(stderr, "Heap object, cancel, auto deletion: start\n");
  s_is_deleted = false;
  tt = NULL;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't initialize a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, true) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_chrono_nanosleep(5LL * 1000LL * 1000LL * 1000LL, NULL);
  if (lagopus_thread_cancel((lagopus_thread_t *)&tt) != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't cancel the thread.\n");
  }
  lagopus_chrono_nanosleep(2LL * 1000LL * 1000LL * 1000LL, NULL);
  if (s_is_deleted == false) {
    lagopus_exit_fatal("The thread object must be freed and "
                       "the flag must be true.\n");
  }
  fprintf(stderr, "Heap object, cancel, auto deletion: end\n\n");

  /*
   * Stack object cancel, auto deletion
   */
  fprintf(stderr, "Stack object, cancel, auto deletion: start\n");
  s_is_deleted = false;
  tt = &ttr;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't initialize a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, true) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_chrono_nanosleep(5LL * 1000LL * 1000LL * 1000LL, NULL);
  if (lagopus_thread_cancel((lagopus_thread_t *)&tt) != LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't cancel the thread.\n");
  }
  lagopus_chrono_nanosleep(2LL * 1000LL * 1000LL * 1000LL, NULL);
  if (s_is_deleted == false) {
    lagopus_exit_fatal("The thread object must be freed and "
                       "the flag must be true.\n");
  }
  fprintf(stderr, "Stack object, cancel, auto deletion: end\n\n");

  /*
   * Timed wait
   */
  fprintf(stderr, "Timed wait: start\n");
  tt = &ttr;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't initialize a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, false) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  if (lagopus_thread_wait((lagopus_thread_t *)&tt,
                          5LL * 1000LL * 1000LL * 1000LL) !=
      LAGOPUS_RESULT_TIMEDOUT) {
    lagopus_exit_fatal("Must be timed out.\n");
  }
  test_thread_request_stop(tt);
  if (lagopus_thread_wait((lagopus_thread_t *)&tt, -1) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't wait the thread.\n");
  }
  lagopus_thread_destroy((lagopus_thread_t *)&tt);
  fprintf(stderr, "Timed wait: end\n\n");

  /*
   * Force destroy
   */
  fprintf(stderr, "Force destroy: start\n");
  s_is_deleted = false;
  tt = NULL;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't create a test thread object.\n");
  }
  if (lagopus_thread_start((lagopus_thread_t *)&tt, false) !=
      LAGOPUS_RESULT_OK) {
    lagopus_exit_fatal("Can't start a thread.\n");
  }
  lagopus_thread_destroy((lagopus_thread_t *)&tt);
  if (s_is_deleted == false) {
    lagopus_exit_fatal("The thread object must be freed and "
                       "the flag must be true.\n");
  }
  fprintf(stderr, "Force destroy: end\n\n");

  /*
   * Force destroy, not started
   */
  fprintf(stderr, "Force destroy, not started: start\n");
  s_is_deleted = false;
  tt = NULL;
  if (test_thread_create(&tt, 100) != true) {
    lagopus_exit_fatal("Can't create a test thread object.\n");
  }
  lagopus_thread_destroy((lagopus_thread_t *)&tt);
  if (s_is_deleted == false) {
    lagopus_exit_fatal("The thread object must be freed and "
                       "the flag must be true.\n");
  }
  fprintf(stderr, "Force destroy, not started: end\n\n");

  ret = 0;
  fprintf(stderr, "Pthread wrapper check: end\n");

  return ret;
}