|
最简单的多线程:可是为什么结果却是依次执行te s t 1和te s t 2呢?
#include <stdio.h>
#include <pthread.h>
void *test1(void *)
{
for(int i = 0; i < 10; i++)
printf("test1 complete\n");
}
void *test2(void *)
{
for(int i = 0; i < 10; i++)
printf("test2 complete\n");
}
int main()
{
pthread_t thread1, thread2;
pthread_create(&thread1, NULL, test1, NULL);
pthread_create(&thread2, NULL, test2, NULL);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
return 0;
} |
|