#2
iotek2011-09-21 15:08
|
#include<stdio.h>
#include<pthread.h>
int x=1,sum;
void sumx(void)
{
int i = 0;
x=1;
for(i=0;i<100;i++)
{
sum=sum+x;
}
printf("%d %d %d\n",i,x,sum)
}
void sext(void)
{
x=0;
}
int main(void)
{
pthread_t id1,id2;
int i,ret;
ret = pthread_create(&id1,NULL,(void *)sumx,NULL);
if(ret!=0)
{
printf("error");
exit(1);
}
ret = pthread_create(&id2,NULL,(void *)setx,NULL);
if(ret!=0)
{
printf("error");
exit(1);
}
pthread_join(id1,NULL);
pthread_join(id2,NULL);
printf("%d",sum);
return(0);
}
我多次得出的答案是i=100,x=1;sum=100
sum=100
请问对吗?