Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added more text on proper synchronization

...

In the first case, there is a happen-before relationship between actions such that steps 1 and 2 always occur before steps 3 and 4. However, in the second case, there is no happens-before relationship between any of the steps. Consequently, because there is a sequentially consistent execution that has no happens-before relationship, there is a data race in this example.

Correct synchronization entails deciding on one sequentially consistent execution order and using synchronized methods or blocks to perform all the actions sequentially. For example, the code shown below ensures that there is only one sequentially consistent execution order that performs all the actions of thread 1 before thread 2.

Code Block

public synchronized void doSomething() {
  // Invoke Thread 1
  // Invoke Thread 2
}


Risk Assessment Summary

Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

CON00-J

medium

probable

medium

P8

L2

CON01-J

medium

probable

medium

P8

L2

CON02-J

low

likely

high

P3

L3

CON03-J

low

probable

medium

P4

L3

CON04-J

low

probable

medium

P4

L3

CON05-J

low

probable

medium

P4

L3

CON06-J

low

probable

medium

P4

L3

CON07-J

low

likely

high

P3

L3

CON08-J

low

likely

high

P3

L3

CON09-J

low

probable

medium

P4

L3

CON10-J

low

probable

medium

P4

L3

CON11-J

low

likely

high

P3

L3

CON12-J

low

probable

medium

P4

L3

CON14-J

low

probable

medium

P4

L3

CON15-J

low

likely

low

P9

L2

CON16-J

low

probable

medium

P4

L3

CON17-J

low

probable

low

P6

L2

CON18-J

low

unlikely

medium

P2

L3

CON19-J

low

unlikely

medium

P2

L3

CON20-J

low

probable

high

P2

L3

CON21-J

low

probable

high

P2

L3

CON22-J

low

probable

medium

P4

L3

CON23-J

low

unlikely

medium

P2

L3

CON24-J

low

unlikely

medium

P2

L3

CON25-J

low

unlikely

medium

P2

L3

...