Multiple tasks perform unprotected operations on shared variable
This defect occurs when:
Multiple tasks perform unprotected operations on a shared variable.
At least one task performs a write operation.
If you check for this defect, you can see data races on both atomic and non-atomic operations.
To see data races on non-atomic operations alone, select Data race. Bug Finder considers an operation as atomic if it can be
performed in one machine instruction. For instance, the
operation:
int var = 0;
int is less than the word
size on the target (or pointer size). See Define Atomic Operations in Multitasking Code. If you do not want to use this definition of atomic
operations, turn on this checker.To find this defect, you must specify the multitasking options before analysis. See Multitasking. If your code does not use critical
sections at all, to avoid flagging too many operations, this checker is disabled. To
flag data races involving only atomic operations, use the option -force-data-races.
Data race can result in unpredictable values of the shared variable because you do not control the order of the operations in different tasks.
To fix this defect, protect the operations on the shared variable using critical sections, temporal exclusion or another means. See Protections for Shared Variables in Multitasking Code.
To identify existing protections that you can reuse, see the table and graphs
associated with the result. The table shows each pair of conflicting calls. The
Access Protections column shows existing protections on the
calls. To see the function call sequence leading to the conflicts, click the
icon. For an example, see below.
| Group: Concurrency |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax: DATA_RACE_ALL |
| Impact: Medium |
| CWE ID: 366, 413 |
Configure multitasking manually | Critical section details (-critical-section-begin -critical-section-end) | Data race | Data race through standard library function call | Deadlock | Destruction of locked mutex | Disabling all interrupts (-routine-disable-interrupts -routine-enable-interrupts) | Double lock | Double unlock | Find defects (-checkers) | Missing lock | Missing unlock | Tasks (-entry-points) | Temporally exclusive tasks (-temporal-exclusions-file)