Race Condition within a Thread |
Weakness ID: 366 (Weakness Base) | Status: Draft |
Description Summary
If two threads of execution use a resource simultaneously, there exists the possibility that resources may be used while invalid, in turn making the state of execution undefined.
Scope | Effect |
---|---|
Integrity | The main problem is that -- if a lock is overcome -- data could be altered in a bad state. |
Example 1
(Bad Code)
Example Languages: C and C++
int foo = 0;
int storenum(int num) {
static int counter = 0;
counter++;
if (num > foo) foo = num;
return foo;
}
(Bad Code)
Example Language: Java
public classRace {
static int foo = 0;
public static void main() {
new Threader().start();
foo = 1;
}
public static class Threader extends Thread {
public void run() {
System.out.println(foo);
}
}
}
Phase: Architecture and Design Use locking functionality. This is the recommended solution. Implement some form of locking mechanism around code which alters or reads persistent data in a multi-threaded environment. |
Phase: Architecture and Design Create resource-locking sanity checks. If no inherent locking mechanisms exist, use flags and signals to enforce your own blocking scheme when resources are being used by other threads of execution. |
Nature | Type | ID | Name | View(s) this relationship pertains to![]() |
---|---|---|---|---|
ChildOf | ![]() | 362 | Race Condition | Development Concepts (primary)699 Research Concepts (primary)1000 |
ChildOf | ![]() | 557 | Concurrency Issues | Development Concepts699 |
ChildOf | ![]() | 634 | Weaknesses that Affect System Processes | Resource-specific Weaknesses (primary)631 |
ChildOf | ![]() | 748 | CERT C Secure Coding Section 50 - POSIX (POS) | Weaknesses Addressed by the CERT C Secure Coding Standard (primary)734 |
ParentOf | ![]() | 572 | Call to Thread run() instead of start() | Development Concepts (primary)699 Research Concepts (primary)1000 |
PeerOf | ![]() | 365 | Race Condition in Switch | Research Concepts1000 |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
CLASP | Race condition within a thread | ||
CERT C Secure Coding | POS00-C | Avoid race conditions with multiple threads |
Submissions | ||||
---|---|---|---|---|
Submission Date | Submitter | Organization | Source | |
CLASP | Externally Mined | |||
Modifications | ||||
Modification Date | Modifier | Organization | Source | |
2008-07-01 | Eric Dalci | Cigital | External | |
updated Time of Introduction | ||||
2008-09-08 | CWE Content Team | MITRE | Internal | |
updated Applicable Platforms, Common Consequences, Relationships, Taxonomy Mappings | ||||
2008-11-24 | CWE Content Team | MITRE | Internal | |
updated Relationships, Taxonomy Mappings |