Description Summary State synchronization refers to a set of flaws involving
contradictory states of execution in a process which result in undefined
behavior.
Example 1 (Bad Code) C and C++ static void print(char * string) { char * word;
int counter;
fflush(stdout);
for(word = string; counter = *word++; )
putc(counter, stdout);
} int main(void) { pid_t pid;
if( (pid = fork()) < 0)
exit(-2);
else if( pid == 0)
print("child");
else print("parent\n");
exit(0);
} (Bad Code) Java class read{ private int lcount;
private int rcount;
private int wcount;
public void getRead(){
while ((lcount == -1) || (wcount !=0));
lcount++;
}
public void getWrite(){
while ((lcount == -0);
lcount--;
lcount=-1;
}
public void killLocks(){
if (lcount==0)
return;
else if (lcount == -1)
lcount++;
else lcount--;
}
}
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Page Last Updated:
October 29, 2009
|
|
CWE is a Software Assurance strategic initiative sponsored by the National Cyber Security Division of the U.S. Department of Homeland Security. This Web site is hosted by The MITRE Corporation. Contact cwe@mitre.org for more information. |
|||
