Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
Thread 1: register 0 = flags
Thread 1: register 0 &= ~mask(flag1)
Thread 2: register 0 = flags
Thread 2: register 0 &= ~mask(flag2)
Thread 1: register 0 |= 1 << shift(flag1)
Thread 1: flags = register 0
Thread 2: register 0 |= 2 << shift(flag2)
Thread 2: flags = register 0

Compliant Solution (bit-field, C++11 and

...

later,

...

mutex)

This compliant solution protects all accesses of the flags with a mutex, thereby preventing any data races.

...

Although the race window is narrow, an assignment or an expression can evaluate improperly because of misinterpreted data resulting in a corrupted running state or unintended information disclosure.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

CON52-CPP

Medium

Probable

Medium

P8

L2

Automated Detection

ToolVersionCheckerDescription
Astrée

Include Page
Astrée_V
Astrée_V

read_write_data_race
write_write_data_race
Supported
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC++-CON52
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

CONCURRENCY.DATARACE

Data Race

Coverity6.5RACE_CONDITIONFully implemented
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C++1774, C++1775
Parasoft C/C++test

Include Page
Parasoft_V
Parasoft_V

CERT_CPP-CON52-aUse locks to prevent race conditions when modifying bit fields
Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C++: CON52-CPPChecks for data races (rule partially covered)

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

Bibliography

[ISO/IEC 14882-2014]Subclause 1.7, "The C++ memory model"

...


...

Image Modified Image Modified Image Modified