qfedu-linux-advanced-level/day6/thread2.c

21 lines
444 B
C
Raw Permalink Normal View History

2023-08-21 19:45:29 +08:00
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *task1(void *data)
{
printf("当前线程号(%ld): %s\n", pthread_self(), (char *)data);
// return NULL;
getchar();
}
int main()
{
pthread_t tid;
// 子线程成功之后,则会自动启动线程
int ret = pthread_create(&tid, NULL, task1, "hello");
printf("主线程(%ld)退出\n", pthread_self());
// sleep(3);
getchar();
return 0;
}