DOC PREVIEW
CMU CS 15410 - Synchronization

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:

15-410, F’04- 1 -Synchronization #1Sep. 17, 2004Dave EckhardtDave EckhardtBruce MaggsBruce MaggsL08b_Synch15-410“My computer is 'modern'!”15-410, F’04- 2 -SynchronizationProject 0 feedback planProject 0 feedback planFirst step: red ink on paperSoon: scores (based mostly on test outcomes)Project 1 alertsProject 1 alerts“make print” must workPlease check for completenessDoxygen documenation must buildPlease check for completeness15-410, F’04- 3 -Project 0 Common ThemesStyle/structureStyle/structureIntegers instead of #defined tokens“2” is not better than “TYPE_DOUBLE”It is much much much worseDon't ever do that“Code photocopier” - indicates a problem, often seriousBad variable/function namesinitialize() should not terminateint i; /* number of frogs */ ⇐ Don't apologize; fix the problem!Excessively long functionswhile(1) should be rare Don't make us read...False comments, dead code, extra copies of codeHarry Bovik did not help you write your P015-410, F’04- 4 -Project 0 Common ThemesStyle/structureStyle/structureCode is read by peopleUsYour partnerYour manager...Don't make it painful for usor else...15-410, F’04- 5 -Project 0 Common ThemesRobustnessRobustnessNot checking syscall returns (e.g., tmpfile())Not finding last function / not handing unnamed functionMemory leak (no need for malloc() at all!)File-descriptor leak15-410, F’04- 6 -Project 0 Common ThemesNot following specNot following specHand-verifying addresses (compare vs. 0x0804... 0xc000...)Approximating arg-offset infoInstead of getting it from the table!!Give up via exit() ⇐ caller never authorized that!Stopping trace at hard-coded function nameSemantic mismatchSemantic mismatch\b is a “backspace character”Clever hack to “undo” a comma in the output stream?Only when the output stream is a terminal!!!Instead of fixing the wrong thing, do the right thing15-410, F’04- 7 -OutlineMe vs. Chapter 7Me vs. Chapter 7Mind your P's and Q'sAtomic sequences vs. voluntary de-scheduling “ Sim City” exampleYou will need to read the chapterHopefully my preparation/review will clarify it15-410, F’04- 8 -OutlineAn intrusion from the “ real world”An intrusion from the “ real world”Two fundamental operationsTwo fundamental operationsThree necessary critical-section propertiesThree necessary critical-section propertiesTwo-process solutionTwo-process solutionN-process “Bakery Algorithm”N-process “Bakery Algorithm”15-410, F’04- 9 -Mind your P's and Q'sWhat you writeWhat you write choosing[i] = true; number[i] = max(number[0], number[1], ...) + 1; choosing[i] = false;What happens...What happens... number[i] = max(number[0], number[1], ...) + 1; choosing[i] = false;15-410, F’04- 10 -Mind your P's and Q'sWhat you writeWhat you write choosing[i] = true; number[i] = max(number[0], number[1], ...) + 1; choosing[i] = false;Or maybe this happens...Or maybe this happens... choosing[i] = false; number[i] = max(number[0], number[1], ...) + 1;“ Computer Architecture for $200, Dave” ...“ Computer Architecture for $200, Dave” ...15-410, F’04- 11 -My computer is broken?!No, your computer is No, your computer is "modern""modern"Processor "write pipe" queues memory stores...and coalesces "redundant" writes!Crazy?Crazy?Not if you're pounding out pixels!CPUMemorychoosing[i] falsenumber[i] 45choosing[i] true15-410, F’04- 12 -My computer is broken?!Magic "memory barrier" instructions available...Magic "memory barrier" instructions available......stall processor until write pipe is emptyOk, now I understandOk, now I understandProbably not! http://www.cs.umd.edu/~pugh/java/memoryModel/ “ Double-Checked Locking is Broken” DeclarationSee also "release consistency"Textbook's memory modelTextbook's memory model...is “ what you expect”Ok to use simple model for homework, exams15-410, F’04- 13 -Synchronization FundamentalsTwo fundamental operationsTwo fundamental operationsAtomic instruction sequenceVoluntary de-schedulingMultiple implementations of eachMultiple implementations of eachUniprocessor vs. multiprocessorSpecial hardware vs. special algorithmDifferent OS techniquesPerformance tuning for special casesBe Be very clearvery clear on features, differences on features, differences15-410, F’04- 14 -Synchronization FundamentalsMultiple client abstractionsMultiple client abstractionsTextbook coversTextbook coversSemaphore, critical region, monitorVeryVery relevant relevantMutex/condition variable (POSIX pthreads)Java "synchronized" keyword (3 uses)15-410, F’04- 15 -Synchronization FundamentalsTwo Fundamental operationsTwo Fundamental operations⇒ Atomic instruction sequence Voluntary de-scheduling15-410, F’04- 16 -Atomic instruction sequenceProblem domainProblem domainShort sequence of instructionsNobody else may interleave same sequenceor a "related" sequence“Typically” nobody is competing15-410, F’04- 17 -Non-interferenceMultiprocessor simulation (think: “Sim City” )Multiprocessor simulation (think: “Sim City” )Coarse-grained “ turn” (think: hour)Lots of activity within turnThink: M:N threads, M=objects, N=#processorsMostMost cars don't interact in a game turn... cars don't interact in a game turn...Must model those that do!15-410, F’04- 18 -CommerceCustomer 0 Customer 1cash = store->cash; cash = store->cash;cash += 50; cash += 20;wallet -= 50; wallet -= 20;store->cash = cash; store->cash = cash;Should the store call the police?Is deflation good for the economy?15-410, F’04- 19 -Commerce – ObservationsInstruction sequences are “ short”Instruction sequences are “ short”Ok to force competitors to waitProbability of collision is "low"Probability of collision is "low"Many non-colliding invocations per secondMust not use an expensive anti-collision approach!Oh, just make a system call...Common (non-colliding) case must be fast15-410, F’04- 20 -Synchronization FundamentalsTwo Fundamental operationsTwo Fundamental operations Atomic instruction sequence ⇒ Voluntary de-scheduling15-410, F’04- 21 -Voluntary de-schedulingProblem domainProblem domain“Are we there yet?”“Waiting for Godot”Example - "Sim City" disaster daemonExample - "Sim City" disaster daemonwhile (date < 1906-04-18)


View Full Document

CMU CS 15410 - Synchronization

Download Synchronization
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 Synchronization 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 Synchronization 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?