AlexLecture_AdvancedState

AlexLecture_AdvancedState - Modeling Concurrency and...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Modeling Concurrency and Synchronization in UML Thread Lifecycle (1/2) Runnable Thread Ready Running Blocked dispatch yield resume suspend Created start 2 Terminated stop stop end stop
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Thread Lifecycle (2/2) Take a closer look: running ready context switch context switch wait/lock signal/unlock 3 suspended Sequence Diagram View sd scenario 1 Active object Passive object b : sharedBuffer startWrite() p:Producer c : Consumer startRead() thread is running thread is ready Thread is suspended 4 Snapshot of execution in progress Thread is not running in this object
Background image of page 2
3 Context Switch: Concept A context switch is the simultaneous transitioning of: one thread from the ready state to the running state AND the previously running thread from the running state to another state (ready or suspended). 5 Context Switch in Sequence Diagram bhd B f f Pd C sd scenario 2 b : sharedBuffer startWrite() p:Producer c : Consumer startRead() 6 Producer switches out, consumer switches in … Consumer suspends, producer switches in …
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Monitors Class-like programming construct that allows at most one thread to execute concurrently Implemented by associating a lock with each monitor object Threads that execute the methods of a monitor object must: obtain the monitor lock before doing anything else in the method release the lock just prior to returning. 7 Monitor Synchronization When a thread attempts to acquire a monitor lock that is held by another thread: the thread that made the failed attempt suspends (i.e., changes state from running to suspended). If the operating system causes a thread running within a monitor to yield (context switch out), the thread will not release the lock before yielding. 8
Background image of page 4
5 sd scenario 3 State labels - producer enters and obtains lock Sequence Diagram : BoundedBuffer : LineConsumer : LineProducer putLine(“d”) locked; getLine() Consumer fails to obtain 9 unlocked; Producer releases lock before returning the lock; suspends Condition Synchronization Counting variables are used to encode the synchronization state of a shared resource. Conditions are predicates formed over one or more counting variables counting variables. Condition variables are associated with conditions and used: by a waiting thread to register interest in a change in the associated condition CV.wait() 10 by a running thread to inform registered waiting threads of changes in the associated condition.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/14/2009 for the course CSE 335 taught by Professor Kraemer during the Fall '08 term at Michigan State University.

Page1 / 15

AlexLecture_AdvancedState - Modeling Concurrency and...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online