# 如何创建一个线程

Issue

欢迎在 Issue 中交流与讨论: Issue 164 (opens new window)

创建一个最简单的线程

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void *thread_function(void *arg) {
  printf("hello, world\n");
  sleep(10);
}

int main() {
  pthread_t thread;

  pthread_create(&thread, NULL, thread_function, NULL);
  pthread_join(thread, NULL);
}

执行它

$ gcc thread.c -std=c99 -lpthread && ./a.out
hello, world
Last Updated: 1/17/2021, 2:02:56 PM