DOC PREVIEW
CMU CS 15410 - Lecture

This preview shows page 1-2-3-18-19-37-38-39 out of 39 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 3915-410, F’04- 1 -The ThreadSep. 15, 2004Dave EckhardtDave EckhardtBruce MaggsBruce MaggsL07_Thread15-410“Maybe the world has enough sokoban implementations?”15-410, F’04- 1 -SynchronizationProject 1Project 1Should have much of console workingShould have some progress (at least design) for kbd, timerWrite good codeWrite good codeConsole driver will be used (and extended) in P315-410, F’04- 1 -Book Report GoalsSome of you are going to grad. schoolSome of you are going to grad. schoolSome of you are wondering about grad. schoolSome of you are wondering about grad. schoolSome of you are Some of you are inin grad. school grad. schoolYou should be able to read a Ph.D. dissertationMore generallyMore generallyLooking at something in depth is differentNot like a textbook15-410, F’04- 1 -Book Report GoalsThere's more than one way to do itThere's more than one way to do itBut you don't have time to try all the ways in 410Reading about other ways is good, maybe funHabituationHabituationLong-term career development requires studyWriting skills (a little!)Writing skills (a little!)“Summarizing” a book in a page is tough15-410, F’04- 1 -Book ReportRead the “handout”Read the “handout”Browse the already-approved listBrowse the already-approved listPick something (soon)Pick something (soon)Don't make me stop the car...Read a bit before you sleep at nightRead a bit before you sleep at nightor: before you sleep in the morningand/or: Thanksgiving breakRecommended by previous OS students!Recommended by previous OS students!15-410, F’04- 1 -Road MapThread lectureThread lectureSynchronization lecturesSynchronization lecturesProbably threeYield lectureYield lectureThis is importantThis is importantWhen you leave here, you will use threadsUnderstanding threads will help you understand the kernelPlease make sure you Please make sure you understandunderstand threads threadsWe'll try to help by assigning you P215-410, F’04- 1 -OutlineTextbook chaptersTextbook chaptersAlready: Chapters 1 through 4Today: Chapter 5 (roughly)Soon: Chapters 7 & 8Transactions (7.9) will be deferred15-410, F’04- 1 -OutlineThread = schedulable registersThread = schedulable registers(that's all there is)Why threads?Why threads?Thread flavors (ratios)Thread flavors (ratios)(Against) cancellation(Against) cancellationRace conditionsRace conditions1 simple, 1 ouchMake sure you really understand this15-410, F’04- 1 -Single-threaded ProcessStackCodeDataHeapRegistersstdinstdouttimer15-410, F’04- 1 -Multi-threaded ProcessstdinstdouttimerCodeDataHeapSt ackRegistersSt ackRegistersSt ackRegisters15-410, F’04- 1 -What does that mean?Three stacksThree stacksThree sets of “local variables”Three register setsThree register setsThree stack pointersThree %eax's (etc.)Three Three schedulable RAM mutatorsschedulable RAM mutators(heartfelt but partial apologies to the ML crowd)Three potential bad interactionsThree potential bad interactions15-410, F’04- 1 -Why threads?Shared access to data structuresShared access to data structuresResponsivenessResponsivenessSpeedup on multiprocessorsSpeedup on multiprocessors15-410, F’04- 1 -Shared access to data structuresDatabase server for multiple bank branchesDatabase server for multiple bank branchesVerify multiple rules are followedAccount balanceDaily withdrawal limitMulti-account operations (transfer)Many accesses, each modifies tiny fraction of databaseServer for a multi-player gameServer for a multi-player gameMany playersAccess (& update) shared world stateScan multiple objectsUpdate one or two objects15-410, F’04- 1 -Shared access to data structuresProcess per player?Process per player?Processes share objects only via system callsHard to make game objects = operating system objectsProcess per game object?Process per game object?“Scan multiple objects, update one”Lots of message passing between processesLots of memory wasted for lots of processesSlow15-410, F’04- 1 -Shared access to data structuresThreadThread per player per playerGame objects inside single memory address spaceEach thread can access & update game objectsShared access to OS objects (files)Thread-switch is cheapThread-switch is cheapStore N registersLoad N registers15-410, F’04- 1 -Responsiveness““Cancel” button vs. decompressing large JPEGCancel” button vs. decompressing large JPEGHandle mouse click during 10-second processMap (x,y) to “cancel button” areaVerify that button-release happens in button area of screen...without JPEG decompressor understanding clicks15-410, F’04- 1 -Multiprocessor speedupMore CPUs can't help a single-threaded process!More CPUs can't help a single-threaded process!PhotoShop color dither operationPhotoShop color dither operationDivide image into regionsOne dither thread per CPUCan (sometimes) get linear speedup15-410, F’04- 1 -Kinds of threadsUser-space (N:1)User-space (N:1)Kernel threads (1:1)Kernel threads (1:1)Many-to-many (M:N)Many-to-many (M:N)15-410, F’04- 1 -User-space threads (N:1)Internal threadingInternal threadingThread library adds threads to a processThread switch just swaps registersSmall piece of asm codeMaybe called yield()CodeDataHeapStackStackRegis tersStack15-410, F’04- 1 -User-space threads (N:1)+ No change to operating system+ No change to operating system- System call probably blocks all “threads”- System call probably blocks all “threads”“The process” makes a system callKernel blocks “the process”(special non-blocking system calls can help)- “Cooperative scheduling” awkward/insufficient- “Cooperative scheduling” awkward/insufficientMust manually insert many calls to yield()- Cannot go faster on multiprocessor machines- Cannot go faster on multiprocessor machines15-410, F’04- 1 -Pure kernel threads (1:1)OS-supported threadingOS-supported threadingOS knows thread/process ownershipMemory regions shared & reference-countedCodeDataHeapStackRegistersStackRegistersStackRegisters15-410, F’04- 1 -Pure kernel


View Full Document

CMU CS 15410 - Lecture

Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?