CO538 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for double-buffering
2000 |
Re. the 2000 exam paper question 6(h). Have we covered the double buffering required to prevent the breaking of parallel usage rules with Java objects? If you could point me in the right direction, it'd be appreciated.
Double buffering is a simple idea. The sender process declares two objects of the type that it's going to output - these are the "buffers". In each loop, it sets up one of them and sends it. It switches between which object to use after each loop - the first loop it uses object 1, the second loop it uses object 2, the third loop it uses object 1 again, the fourth time it uses object 2 again etc.
The receiving process need not be aware of these switches. In each cycle, it just inputs an object, processes it and forgets about it. [For example, the B process of part (g) needs no change.]
Now, when the sender is working on obect 2, the receiver will be working on object 1 - and vice-versa. Each process is always working on different objects and there is no race hazard. The switching between which object to use is synchronised by the (once-per-cycle) channel communication.
That's all there is to it. For information on its use in anger, see the (javadoc) documentation on:
jcsp.plugNplay.ints.ParaplexInt
and:
jcsp.lang.parallel (the "High Level" and "Low Level" examples)
Keywords: double-buffering , jcsp
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |