Transcript Mutexes

Section 4
Advanced
Mutexes
Adv-1
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Mutexes
• 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();
Adv-2
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Animating Mutexes
• Rhapsody cannot display in animation, the
value of attributes of type OMProtected.
• In order to use animation, the property
AnimateAttributes for the attribute must be
set to FALSE.
Adv-3
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Animating Attributes
• For animating attributes of a user defined type,
the same problem can occur.
• To allow animation:
– either set the property AnimateAttributes to FALSE
– or add a global function operator<< for the user
defined type
ostream& operator<<(ostream& out, const tDate& d) {
out << d.day << "/" << d.month << "/" << d.year;
return out;
};
– Or use the InstrumentationFunctionName
Adv-4
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Instrumentation Function Name I
• To animate an attribute of type tTempUnits that
is an enum of CELSIUS and FAHRENHEIT :
• Add a function showTempUnits as follows :
Adv-5
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Instrumentation Function Name II
• Set the Animate and AnimateArguments
properties for this function to False :
Adv-6
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Instrumentation Function Name III
• For each attribute of type tTempUnits, set the
InstrumentationFunctionName to
showTempUnits
Adv-7
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Instrumentation Function Name IV
• To generate this
operation only during
animation, the
following properties
can be set for this
function.
New line
Adv-8
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Instrumentation Function Name V
Adv-9
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
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.
Adv-10
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Unguarded Behavior
Current read()
operation is
interrupted by
another.
Adv-11
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
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.
Adv-12
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Guarded Behavior
Concurrent
read()
operation is
blocked by
mutex and
is executed
when current
read() ends.
Adv-13
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Guarded Operation : Code
Adv-14
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001
Guarding Relations
• Rhapsody can also use the mutex
OMProtected to guard access to a particular
relation to stop concurrent access.
• This can be done by setting the property
isGuarded from none to all ( mutator &
accessor operations ) or just mutator.
Adv-15
Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001