#include
void *myThread1(void)
{
printf("This is the 1st pthread,created by zieckey.\n");
}
void *myThread2(void)
{
printf("This is the 2st pthread,created by zieckey.\n");
}
int main()
{
int i=0, ret=0;
pthread_t id1,id2;
ret = pthread_create(&id1, NULL, (void*)myThread1, NULL);
if (ret)
{
printf("Create pthread error!\n");
return 1;
}
ret = pthread_create(&id2, NULL, (void*)myThread2, NULL);
if (ret)
{
printf("Create pthread error!\n");
return 1;
}
pthread_join(id1, NULL);
pthread_join(id2, NULL);
return 0;
}
运行结果是
This is the 2st pthread,created by zieckey.
This is the 1st pthread,created by zieckey.
为什么是2先再1,还有就是创建多个线程,还是1最后显示,其他都是按照顺序显示的,例如
This is the 2st pthread,created by zieckey.
This is the 3st pthread,created by zieckey.
This is the 4st pthread,created by zieckey.
This is the 1st pthread,created by zieckey.
为什么??线程创建与执行关系是如何的?大神们快过来啊(T T)、!!