/* * ReaderWriterRMon.java (Implements Readers/Writers Reader.) * * Written by : Nitin Motgi (nmotgi@cs.ucf.edu) * * This file implements Reader problem. * * Portions copyright(c) 2000 to School of Electrical Engineering and * Computer Science, UCF, Orlando. * * Use and distribution of this source code are strictly governed by * terms and conditions set by the authors. * * $Id : ReaderWriterRMon.java, v1.0.0 02/15/2001. $ * * Revision History Revisited: * */ /* Start of ReaderWriterRMon.*/ public class ReaderWriterRMon extends Thread{ /* Each consumer is given an ID so that the higher level routine can interact with a specific Reader.*/ int nID; /* This is up level pointer points to the parent class which provides mechanism for synchronization.*/ ReaderWriterMon RWMon; /* End condition indicator set to push the Producer from endlessly producing an item and put in the queue.*/ boolean bEndCondition; public int nToken; /* * This function is constructor for this class. */ public ReaderWriterRMon(int nID,ReaderWriterMon RWMon){ this.nID = nID; /* Store ID.*/ this.RWMon = RWMon; /* Pointer to Higher class.*/ bEndCondition = true; /* Produce one item and put in shared data structure.*/ nToken = -1; }/* End of ReaderWriterRSem.*/ /* * This program is heart of this thread. */ public void run(){ int nPrevToken=-1; /* Till the indicator turns false.*/ while(bEndCondition){ if(RWMon.StartRead(nToken,this) == -1) continue; RWMon.ReadDatabase(this); if(nPrevToken == nToken){ nPrevToken = nToken; }/* End if.*/ RWMon.EndRead(); }/* End of while.*/ }/* End of run.*/ /* * Sets the end codition to true or false. */ public void SetEndCondition(boolean bState){ bEndCondition = bState; }/* End of SetEndCondition.*/ }/* End of ReaderWriterRMon.*/