21 lines
444 B
C
21 lines
444 B
C
|
#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;
|
||
|
}
|