#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#define PRINT_MAX 10
void *MyThread(void *arg)
{
int cnt;
for (cnt = 0; cnt < PRINT_MAX; cnt++) {
sleep(1);
printf("[%s][%d] print cnt %d.\n", __FUNCTION__, __LINE__, cnt);
}
return NULL;
}
int main()
{
int ret;
int cnt;
pthread_t pthreadId;
ret = pthread_create(&pthreadId, NULL, MyThread, NULL);
if (ret != 0) {
printf("pthread_create failed.\n");
return -1;
}
(void)pthread_detach(pthreadId);
printf("hello world~\n");
for (cnt = 0; cnt < PRINT_MAX; cnt++) {
sleep(2);
printf("[%s][%d] print cnt %d.\n", __FUNCTION__, __LINE__, cnt);
}
sleep(1);
return 0;
}
makefile.c:
hello : main.c
gcc main.c -o hello