I wanna use int array in shared memory,after writing 1,2,3 into it,I expect read it like this:1,2,3.But I read this:3,2,1.I don't know why
write code:
int *gIn;
int main(){
int id;
id = shmget(0x666,1024,IPC_CREAT|0666);
gIn=(int *)shmat(id,NULL,0);
*gIn++=10;
*gIn++=20;
*gIn++=30;
sleep(10);
return 0;
}
read code:
int *gIn;
int main(){
int id;
id = shmget(0x666,1024,IPC_CREAT|0666);
gIn=(int *)shmat(id,NULL,0);
printf("%d|%d|%d\n",*gIn++,*gIn++,*gIn++);
return 0;
}
I expect the output of read process to be 10|20|30,but the actual output is 30|20|10.It's very strange.I don't know why