JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
Multiple execution threads access a shared piece of data, and at least one of them changes the value of that data, without an explicit synchronization operation to separate the accesses.
CodeSonar infers proper synchronization primarily based on the assumption that accesses to shared memory occur in critical sections defined by the acquisition of mutex locks. In applications that use other synchronization patterns (such as producer/consumer), CodeSonar is likely to issue many false positive Data Race warnings.
| Class Name | Data Race | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mnemonic | CONCURRENCY.DATARACE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
WARNING_FILTER += allow class="Data Race" |
The Data Race analysis will treat a function f() as a thread entry point if f() is passed to any of the following, as described on the Concurrency Models: Thread Entry Points page.
[For programs using object-oriented multithreading APIs only.] The Data Race analysis will treat an object method o.m() as a thread entry point if o is used in a location where a thead entry point is expected and m() matches a THREAD_ENTRY_METHOD_NAMES configuration file rule.
#include <pthread.h>
int count;
void update_count(void){
int tmp = count; /* read without locking */
tmp = tmp+1;
count = tmp; /* 'Data Race' warning issued here */ /* write without locking */
}
void *watch_Y(void *arg){
while (1){
/* If see a yellow object, then... */
update_count();
/* Do yellow-specific tasks. */
}
}
void *watch_R(void *arg){
while (1){
/* If see a red object, then... */
update_count();
/* Do red-specific tasks. */
}
}
int main(void) {
pthread_t Y_pth, R_pth;
int y_res, r_res = 0;
int retval = 0;
y_res = pthread_create(&Y_pth, NULL, watch_Y, "yellow");
r_res = pthread_create(&R_pth, NULL, watch_R, "red");
/* ... */
if (!y_res)
pthread_detach(Y_pth);
if (!r_res)
pthread_detach(R_pth);
return y_res + r_res;
}
In a multithreaded environment, data races can occur in the body of update_count():
Even if the Data Race warning class is enabled, CodeSonar will only perform checking for this class if there is at least one location in the project that invokes one the following threading primitives.
Note in particular that identifying a function with configuration parameter FORCE_THREAD_ENTRY_NAMES or THREAD_ENTRY_METHOD_NAMES is not sufficient to ensure that Data Race checking will be performed.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.