klarz klarz - 2 months ago 22
Java Question

Reentrant Lock - possible outputs?

given lock situation:

enter image description here

I think I got this right but I need to be sure so I'm asking you guys if I made a mistake.

I got two possible outputs for variables "x" and "y" in this programm:

1. Lines 1.1 - 1.7: y = 5,
Lines 2.1 - 2.3: x = 15.

2. Lines 2.1 - 2.3: x = 11,
rest y = 25.


are there any other outputs in this exact situation?

Answer

The lock block on the right had side can occur in one of three places:

  • Before 1.1
  • Between 1.3 and 1.5
  • After 1.7

The values of x and y for these three cases are

  • x = 11, y = 25
  • x = 11, y = 5
  • x = 15, y = 5
Comments