#include <stdio.h>
#include <pthread.h>
void *my_thread(void *arg) // callback function call back
{
int num = 5;
while(1) {
printf("func %s %d \n", __func__, __LINE__);
sleep(1);
num--;
if(num == 0)
break;
}
return NULL; // 线程退出
}
int main(int argc, const char *argv[])
{
pthread_t tid;
int ret = pthread_create(&tid, NULL, my_thread, NULL);
if(ret != 0) {
perror("pthread_create");
return -1;
}
while(1) { // 不要让进程死掉
printf("%s %d \n", __func__, __LINE__);
sleep(1);
}
return 0;
}