I'm writing a simple system call function, and came across some phenomenon I couldn't understand. In the code below, I used a variable "flag" to replace the long bothering "prptr->prhasmsgb" at [1] and [2]. I supposed that it won't cause any difference, but it turned out that the first call to this function, with prptr->prhasmsgb=0, will skip if and enter the switch(). This error is consistent, and I suppose this may have something to do with compiler (gcc)? Also, how does the compiler (gcc) determine what is independent and what to parallelize? I've got no clue on compiler, any advice would be appreciated. Thanks!
ps: The code below is almost what I have in my original code, except for the do something part.
prptr = &proctab[currpid]; /* prptr is a pointer, and below are supposed */
/* dealing with different prptr->prhasmsgb. */
/* prptr->prhasmsgb = (int){0,1,2,3} */
// int flag;
// flag = prptr->prhasmsgb; /* I used flag to replace prptr->prhasmsgb */
// /* if[1] & switch[2] are "paralleled" somehow */
/* case 0 is handled here */
if (prptr->prhasmsgb == 0) { /* [1] once was flag */
do something;
resched(); /* call reschedule */
}
switch (prptr->prhasmsgb) { /* [2] once was flag */
case 1:
do something;
return value;
case 2:
do something;
return value;
case 3:
do something;
return value;
case 0:
/* should never enter case 0 */
default:
return error;
}
flagafter assignment