Each user may input several readwrite operations

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
modify the program such that a user inputs read and write operations to access to the data items. Each user may input several read/write operations accessing to different data items. Each user input is terminated with the character “E”. In addition, you may also increase the processing time for the read and write operations or vary the number of data items in the system such that the change to be blocked due to synchronization will be higher. Part IV: Program Listings Program 1: dataRecord public class dataRec{ private final int IDLE_MODE = 0; //idle mode private final int READ_MODE = 1; //read mode private final int WRITE_MODE = 2; //write mode private final int READ_TIME = 4000; //read process time private final int WRITE_TIME = 10000; //write process time private int state; //IDLE, READ_MODE or WRITE_MODE private int key_id; //primary key of the dataRec private int value; //value of the data /* constructor */ public dataRec(int i_keyId, int i_value){ key_id = i_keyId; state = IDLE_MODE; value = i_value; }
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
/* read operation synchronized - mutual exclusive */ public synchronized int op_read(){ int out_value; /* op state action ------------------------------- READ IDLE -> process READ READ -> block READ WRITE -> block */ while (state != IDLE_MODE){ try { wait(); }catch (InterruptedException e){ } } state = READ_MODE; /* stimulate read process time */ try { Thread.sleep(READ_TIME); }catch (InterruptedException e){ //We've been interrupted: no more messages.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern