• Post Reply Bookmark Topic Watch Topic
  • New Topic

JLS ch.17.10 Example: Possible Swap

 
Vitaly Oblap
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I try to understand the example, given at 17.10 of The Java �Language Specification for

Can you explain me why there are three possible orderings of actions and the resulting states are as follows:
� write a->read a, read b->write b (then ha=2, hb=2, ma=2, mb=2, ya=2, yb=2)
� read a->write a, write b->read b (then ha=1, hb=1, ma=1, mb=1, ya=1, yb=1)
� read a->write a, read b->write b (then ha=2, hb=2, ma=2, mb=1, ya=1, yb=1)
thanks.
 
Pierre Henry
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
� write a->read a, read b->write b (then ha=2, hb=2, ma=2, mb=2, ya=2, yb=2)
� read a->write a, write b->read b (then ha=1, hb=1, ma=1, mb=1, ya=1, yb=1)
� read a->write a, read b->write b (then ha=2, hb=2, ma=2, mb=1, ya=1, yb=1)
Consider hither and yon being scheduled in 2 threads that competes
for 2 operation , read and write, and at init state a=1, b=2 - so we have:
a = b : means: write a, read b
b = a : means: write b, read a
but you cannot predict the order
so you have:
thread op
hither write a
yon read a
hither read b
yon write b
________________ OR
yon read a
hither write a
yon write b
hither read b
_________________ etc
the rule is : you cannot have two simultaneaous read because they are
done in the main memory
that's what it means...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!