AlexLecture_Concurrency

AlexLecture_Concurrency - Concurrency by Time-sliced...

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

View Full Document Right Arrow Icon
1 Concurrency by Time-sliced multiplexing Concurrency Many modern applications perform multiple tasks concurrently Various ways to implement concurrency in an application Each approach comes with its own set of costs and benefit Each approach comes with its own set of costs and benefits More important: Each approach can have a dramatic impact on how one designs every class in the system 2
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 Recall design of document browser vp : … sb : … vpm : … dm : … sd design3 announceNewValue(X) update() retrieve(0, . ..) getLine(X, …) userEvent() ceNewValue(X) 3 retrieve(n, . ..) getLine(X+n, …) announc Example Suppose we want to replace the DocManager with a StreamManager , which continuously reads lines to display from a service over the network. This manager must notify scrollbar and viewport when a new line is read from network scrollbar and viewport when a new line is read from network. Task: Draw a sequence diagram that depicts what happens when the stream manager reads a new line from the network. 4
Background image of page 2
3 Solution sketch vp : … sb : … vpm : … sm : … sd stream serviceNetwork() ??? announceNewValue(X) update() retrieve(0, . ..) getLine(X, …) ceNewValue(X) 5 retrieve(n, . ..) getLine(X+n, …) announc Question Who generates this call to serviceNetwork? Where would we place it in our application code? 6
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 Design of function main() int main (void) { … StreamManager* sm = new StreamManager(…); MyScrollBar* sb = new MyScrollBar(…); MyViewPort* vp = new MyViewPort(…); MyViewPortModel* vpm = new MyViewPortModel(…); sb->registerListener(vpm); sb->registerListener(vp); vp->setModel(vpm); vpm->setModel(sm); >i t L i t ( b ) 7 sm->registerListener(sb); return Fl::run(); } Question: Will this cause serviceNetwork() to be invoked periodically? By whom? Recall the previous ScrollBar and DocManager collaboration Application listene mode main sb : . .. dm : . .. listener model ... 8 Event Queue Operating system Mouse
Background image of page 4
5 Entering “collaboration phase” Application listene mode FL::run() main sb : . .. dm : . .. listener model ... 9 Event Queue Operating system Mouse Step 1.1: App checks event queue listene mode FL::run() main sb : . .. dm : . .. listener model ... 10 Event Queue Mouse
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Step 1.2: App blocks on empty queue Application listene mode FL::run() main sb : . .. dm : . .. listener model ... 11 Event Queue Operating system Mouse User then moves scrollbar handle listene mode FL::run() main sb : . .. dm : . .. listener model ... 12 Event Queue Mouse
Background image of page 6
7 Step 1.3: application “wakes” when event arrives Application listene mode FL::run() main sb : . .. dm : . .. listener model ... 13 Event Queue Operating system Mouse leftPress Step 1.4: app “pulls” event off queue listene mode FL::run() main sb : . .. dm : . .. listener model ... 14 Event Queue Mouse
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Step 2.1: app “dispatches” event to sb Application listene mode FL::run() p.pressEvent() main sb : . .. dm : . .. listener model ... 15 Event Queue Operating system Mouse Step 2.2: sb notifies its listener(s) listene mode FL::run() p.pressEvent() main sb : . .. dm : . ..
Background image of page 8
Image of page 9
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 / 22

AlexLecture_Concurrency - Concurrency by Time-sliced...

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

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