DOC PREVIEW
UCF COT 4810 - Concurrent Programming

This preview shows page 1-2-3-4-29-30-31-32-59-60-61-62 out of 62 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 62 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 62 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 62 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 62 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 62 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 62 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 62 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 62 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 62 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 62 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 62 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 62 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 62 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Concurrent ProgrammingWhat is concurrency?Slide 3AssumptionsWhy Use Concurrency?Concurrency Example: Producer / ConsumerProducer / Consumer – OutputSlide 8Critical Section (CS)Mutual ExclusionImplementing Mutual ExclusionMutual Exclusion – Version 1Version 1 – Is Mutual Exclusion Guaranteed?Version 1 – Guarantees mutual exclusionSlide 15Slide 16Slide 17Slide 18Slide 19Version 1 – Are Both Constraints Satisfied?Version 1 – Violates Constraint1Version 1 – Any new problems?Version 1 – Lockstep Synchronization ProblemSlide 24Slide 25Version 1 – AssessmentMutual Exclusion – Version 2Version 2 – Is Constraint1 Satisfied Now?Version 2 – Obeys Constraint1Slide 31Version 2 – Does the Lockstep Synchronization Problem Persist?Version 2 – Resolves Lockstep SynchronizationSlide 34Slide 35Version 2 – Any new problems?Version 2 – Violates Mutual ExclusionSlide 38Slide 39Version 2 – AssessmentMutual Exclusion – Version 3Version 3 – Any new problems?Version 3 – Introduces DeadlockSlide 44Slide 45Version 3 – AssessmentMutual Exclusion – Version 4Version 4 – Any new problems?Mutual Exclusion – Introduces Indefinite PostponementSlide 51Slide 52Slide 53Slide 54Version 4 – AssessmentMutual Exclusion – Dekker’s AlgorithmDijkstra’s development of Dekker’s AlgorithmDekker’s Algorithm – AssessmentPeterson’s AlgorithmSlide 61Mutual Exclusion PrimitivesSlide 63James Adkison Concurrent ProgrammingWorks CitedConcurrentProgrammingJames Adkison02/28/2008What is concurrency?“happens-before relation – A happens before B if A and B belong to the same process and A occurred before B; or A is the sending of a message and B is the receiving of that message” (Deitel)What is concurrency?“concurrent – Two events are concurrent if it cannot be determined which event occurred earlier by following the happens-before relation” (Deitel)AssumptionsUsing a single processor systemWorking with threads, not processesWorking with only two threadsAny level of interleaving is possibleMachine-level instructions are atomic (i.e. are executed indivisibly)Why Use Concurrency?Improved throughputthroughput – Amount of work performed per unit time.Improved responsivenesse.g. responsive GUIAppropriate / Required for problem domainConcurrency Example:Producer / ConsumerProducer:Writes integers 1 – 4 (in order) to a shared buffer and terminatesConsumer:Reads and sums the integers 1 – 4 from the shared bufferDisplay the sum total and terminateProducer / Consumer – OutputCorrect (Desired) Output:Producer writes 1Consumer reads 1Producer writes 2Consumer reads 2Producer writes 3Consumer reads 3Producer writes 4Terminating: Producer.Consumer reads 4Consumer read values totaling: 10.Terminating: Consumer.Producer / Consumer – OutputCorrect (Desired) Output:Producer writes 1Consumer reads 1Producer writes 2Consumer reads 2Producer writes 3Consumer reads 3Producer writes 4Terminating: Producer.Consumer reads 4Consumer read values totaling: 10.Terminating: Consumer.Sample Output:Consumer reads -1Producer writes 1Consumer reads 1Producer writes 2Producer writes 3Consumer reads 3Consumer reads 3Consumer reads values totaling: 6.Terminating: Consumer.Producer writes 4Terminating: producer.Critical Section (CS)“When a thread is accessing shared modifiable data.” (Deitel)Producer / Consumer: the shared mutable bufferint x = 10;Thread1 Thread2Read x Read xWrite 3xWrite -2xCritical SectionMutual Exclusion“Restriction whereby execution by a thread of its critical section precludes execution by other threads of their critical sections.” (Deitel)“Mutual exclusion is crucial to correct execution when multiple threads access shared writable data.” (Deitel)Implementing Mutual ExclusionA purely software solutionConstraint 1:A thread outside of its critical section can not block another thread from entering the critical sectionConstraint 2:A thread must not be indefinitely postponed from entering its critical sectionMutual Exclusion – Version 1// Thread1...while (!done) { // Enter mutual exclusion while ( threadNumber == 2 ); // Critical section threadNumber = 2; // Outside critical section}...// Thread2...while (!done) { // Enter mutual exclusion while ( threadNumber == 1 ); // Critical section threadNumber = 1; // Outside critical section}...int threadNumber = 1; // globally accessible to Thread1 and Thread2Version 1 –Is Mutual Exclusion Guaranteed?// Thread1...while (!done) { // Enter mutual exclusion while ( threadNumber == 2 ); // Critical section threadNumber = 2; // Outside critical section}...// Thread2...while (!done) { // Enter mutual exclusion while ( threadNumber == 1 ); // Critical section threadNumber = 1; // Outside critical section}...int threadNumber = 1; // globally accessible to Thread1 and Thread2Version 1 –Guarantees mutual exclusion// Thread1...while (!done) { // Enter mutual exclusion while ( threadNumber == 2 ); // Critical section threadNumber = 2; // Outside critical section}...// Thread2...while (!done) { // Enter mutual exclusion while ( threadNumber == 1 ); // Critical section threadNumber = 1; // Outside critical section}...int threadNumber = 1; // globally accessible to Thread1 and Thread2Version 1 –Guarantees mutual exclusion// Thread1...while (!done) { // Enter mutual exclusion while ( threadNumber == 2 ); // Critical section threadNumber = 2; // Outside critical section}...// Thread2...while (!done) { // Enter mutual exclusion while ( threadNumber == 1 ); // Critical section threadNumber = 1; // Outside critical section}...int threadNumber = 1; // globally accessible to Thread1 and Thread2Version 1 –Guarantees mutual exclusion// Thread1...while (!done) { // Enter mutual exclusion while ( threadNumber == 2 ); // Critical section threadNumber = 2; // Outside critical section}...// Thread2...while (!done) { // Enter mutual exclusion while ( threadNumber == 1 ); // Critical section threadNumber = 1; // Outside critical section}...int threadNumber = 1; // globally accessible to Thread1 and Thread2Version 1 –Guarantees mutual exclusion// Thread1...while (!done) { // Enter mutual exclusion while ( threadNumber == 2 ); // Critical section threadNumber = 2; // Outside critical section}...//


View Full Document

UCF COT 4810 - Concurrent Programming

Documents in this Course
Spoofing

Spoofing

25 pages

CAPTCHA

CAPTCHA

18 pages

Load more
Download Concurrent Programming
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 Concurrent Programming 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 Concurrent Programming 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?