Ubuntu下gcc编译跑,为什么会存在不等于20000?
int n = 0;
void *fun1(void *a)
{
for (int i = 0; i < 10000; ++i)
{
n++;
}
return NULL;
}
void *fun2(void *a)
{
for (int i = 0; i < 10000; ++i)
{
n++;
}
return NULL;
}
int main()
{
pthread_t tid1, tid2;
pthread_create(&tid1, NULL, fun1, NULL);
pthread_create(&tid2, NULL, fun2, NULL);
pthread_join(tid1, NULL);
pthread_join(tid1, NULL);
printf("%d\n",n);
return 0;
}