#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
void *thread(void *str)
{
int i;
for (i = 0; i < 10; ++i)
{
sleep(2);
printf( "This in the thread : %d\n" , i );
}
return NULL;
}
int main()
{
pthread_t pth;
int i;
int ret = pthread_create(&pth, NULL, thread, (void *)(i));//此处 下面2个 没有阻塞,则结果 进程直接往下运行,上面thread线程直接没有运行 就直接退出了
//pthread_join(pth, NULL);
printf("123\n");
for (i = 0; i < 10; ++i)
{
//sleep(1);
printf( "This in the main : %d\n" , i );
}
return 0;
}
#include <unistd.h>
#include <stdio.h>
void *thread(void *str)
{
int i;
for (i = 0; i < 10; ++i)
{
sleep(2);
printf( "This in the thread : %d\n" , i );
}
return NULL;
}
int main()
{
pthread_t pth;
int i;
int ret = pthread_create(&pth, NULL, thread, (void *)(i));//此处 下面2个 没有阻塞,则结果 进程直接往下运行,上面thread线程直接没有运行 就直接退出了
//pthread_join(pth, NULL);
printf("123\n");
for (i = 0; i < 10; ++i)
{
//sleep(1);
printf( "This in the main : %d\n" , i );
}
return 0;
}