C语言 pthread_create() 函数讲解

  #include

  #include

  #include

  #include

  #include

  void printids(const char *s)

  {

  pid_t pid;

  pthread_t tid;

  pid = getpid();

  tid = pthread_self();

  printf("%s pid 퀭 腁%x)

  ", s, (unsigned int) pid, (unsigned int) tid, (unsigned int) tid);

  }

  void * thr_fn(void *arg)

  {

  printids("new thread: ");

  return NULL;

  }

  int main()

  {

  int err;

  pthread_t ntid;

  err = pthread_create(&ntid, NULL, thr_fn, NULL);

  if(err != 0)

  {

  printf("Can't create thread: %s

  ", strerror(err));

  }

  printids("main thread");

  pthread_join(ntid, NULL);

  return EXIT_SUCCESS;

  }