Presentation is loading. Please wait.

Presentation is loading. Please wait.

אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 9 נקודות חשובות בתרגיל 10 Guarded Operation.

Similar presentations


Presentation on theme: "אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 9 נקודות חשובות בתרגיל 10 Guarded Operation."— Presentation transcript:

1 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 9 נקודות חשובות בתרגיל 10 Guarded Operation

2 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט2 מבנה הפרויקט

3 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט3 הבטים שונים (OMD1) ארכיטקטורה של המערכת-מחלקות

4 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט4 הבטים שונים (OMD 2) מבנה של Composite חשוב

5 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט5 הבטים שונים (OMD 3) בניית המערכת

6 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט6 הבטים שונים (OMD 4) מבנה Packages בלי מחלקות

7 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט7 הבטים שונים (OMD 5) מבנה Packages עם מחלקות

8 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט8 בניית מערכת (1): >

9 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט9 בניית מערכת (2): Sys מחלקה המיועדת רק לבנות יתר המופעים Sys::Sys() { Adc::getInstance();}

10 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט10 בניית מערכת (3): Sensor שילוב בין singleton ל association Sensor::Sensor() {itsAdc = Adc::getInstance();}

11 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט11 התנהגות של המערכת: Statecharts

12 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט12 פעולות read() של מחלקות Sensor enum eChannel { VOLTAGE, TEMPERATURE, PRESSURE, CALIBRATION }; int TemperatureSensor::read() { int n; n = itsAdc->read ( TEMPERATURE ); n *= 5; return n; } int PressureSensor::read() {return( 10 * itsAdc->read( PRESSURE ));} int VoltageSensor::read() { int n = itsAdc->read( VOLTAGE ); n *= 3; n /= 2; return n; }

13 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט13 פעולות read() של מחלקת Adc (1)

14 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט14 פעולות read() של מחלקת Adc (2) //file Adc.h class Adc { public: int value;... //etc. } //file Adc.cpp int Adc::read(echannel aChannel) { int i,n; itsMux.select( aChannel ); for ( i=0,n=0; i<8; i++ ) { if ( itsDataIn.isHigh() ) n = ( n << 1 ) + 1; else n = ( n << 1 ) ; } value = n; return n; } //file Mux.h class Mux { private: eChannel channel;... //etc. } //file Mux.cpp void Mux::select (eChannel aChannel) {channel=aChannel;} //file DataIn.cpp bool DataIn::isHigh() { return ( rand() % 2 == 0{;( bool DataIn::isLow() { return (!isHigh());}

15 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט15 Guarded Operation- Mutexs Rhapsody provides OMProtected which is a mutex (or binary semaphore) for protecting consecutive access to devices. OMProtected can be used as follows: –attribute OMProtected myMutex; –free myMutex.free(); –lock myMutex.lock();

16 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט16 Unguarded Access to Adc::read() In the following example, each Sensor calls the Adc::read() operation to measure Voltage / Temperature or Pressure. The read operation selects the appropriate multiplexor input and does eight serial reads on DataIn.

17 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט17 Unguarded Behavior Current read() operation is interrupted by another.

18 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט18 Guarding Operations Rhapsody can use the mutex OMProtected to guard access to a particular operation to stop concurrent access. This can be done by setting the property concurrency from sequential to guarded. All operations in a same class, that are guarded will be guarded by the same mutex.

19 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט19 Guarded Behavior Concurrent read() operation is blocked by mutex and is executed when current read() ends.

20 אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט20 Guarded Operation : Code


Download ppt "אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 9 נקודות חשובות בתרגיל 10 Guarded Operation."

Similar presentations


Ads by Google