This discussion is archived
2 Replies Latest reply: Nov 28, 2011 2:08 AM by 902410 RSS

Main Memory operation in case of threading.

902410 Newbie
Currently Being Moderated
Hi All,

I was recently going through Java VM Spec - version 2 , and Threads section at

http://java.sun.com/docs/books/jvms/second_edition/html/Threads.doc.html#24432

I was at section 8.10 '*Example: Possible Swap*' .

Now in this given example , there is a pic ( unfortunately , I am unable to paste it here) which shows the flow of 2 threads for a given snippet.

In the next line they say

+'The only constraint is that it is not possible both for the write of a to precede the read of a and for the write of b to precede the read of b'+


Now I feel confused because , how is this scenario even possible . How can write of A even happen before the read of B has completed . As per the figure , write of A can only happen after read of B. The whole point I am trying to put is , why should Main Memory even think of ordering .

May be I have not been able to understand the point made earlier in the same document in section 8.2 (*Execution Order and Consistency*)


It is not permitted for an action to follow itself.

The last rule may seem trivial, but it does need to be stated separately and explicitly for completeness. Without the rule, it would be possible to propose a set of actions by two or more threads and precedence relationships among the actions that would satisfy all the other rules but would require an action to follow itself.

Could some one help me on this please. Any small lead in understanding would be very helpful.

Thanks
Abhi
  • 1. Re: Main Memory operation in case of threading.
    EJP Guru
    Currently Being Moderated
    hither() reads b and writes a. yon() reads a and writes b. They are executing concurrently in two different threads.
  • 2. Re: Main Memory operation in case of threading.
    902410 Newbie
    Currently Being Moderated
    Hi ,

    Thanks for reply.

    Yes , I do agree , they are independent of each other .

    My confusion is ,

    1) why should Main memory even try to decide the order in which the read of write should happen . As they are independent , as when Main memory gets the request for read or write , it should perform.

    2) Is there any scenario in which the below case can happen?

    write a->read a,write b -> read b

    And if its not possible, whats the point of explicitly stating

    It is not permitted for an action to follow itself.


    Yes , this might lead to ambiguous scenario , but even with arranging them in order we are unable to predict the solution.

    Beg you pardon, if I am misunderstanding some concept , but I am unable to relate the picture completely .

    Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points