1 / 14

CSE 451

CSE 451. Section February 3, 2000. Agenda. Project comments Homework 3 review Sample exam questions. Project comments. How did it go? What was difficult? How did the hand in go? What can we do to make it easier?. Homework 3. General comments:

love
Download Presentation

CSE 451

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 451 Section February 3, 2000

  2. Agenda • Project comments • Homework 3 review • Sample exam questions

  3. Project comments • How did it go? • What was difficult? • How did the hand in go? • What can we do to make it easier?

  4. Homework 3 • General comments: • You need a mutex around all shared variables • If you have a condition variable and no monitor, you need a mutex • You can’t broadcast on a condition variable in a monitor • Don’t invent new synchronization constructs, unless you implement them with semaphores, mutexes, or condition variables: • “Sleep”, “Awaken”, “Call asynchronous”

  5. Homework 3 problems • Sleeping Barbers • Need to keep a count of waiters, with a mutex • Need to wait for barber to finish cutting hair • Smokers • Easiest to use a monitor. • Need either 3 conditions, or one, and then serial wake-ups • If using semaphores, need to consider case where ingredients arrive out of order

  6. Homework 3 problems (cont) • Line printers: • Best solution: use a condition variable with a priority queue • Other solutions: have one condition variable per caller, and order those • File access • Need to consider case where multiple waiters should be awoken

  7. Sample Problems • Scheduling – SJF, RR, FIFO

  8. Deadlock • Bankers Algorithm

  9. Process States • What is possible? Running Ready Blocked

  10. Safety Void AtomicTransfer(Queue *queue1, Queue *queue2) { Item thing; // thing being transferred queeu1->lock.Acquire(); thing=queue1->dequeue(); if (thing != NULL) { queue2->lock.acquire(); queue2->Enqueue(thing); queue2->lock.release(); } queue1->lock.release(); }

  11. Making Water Int numHydrogen = 0; Semaphore pairOfHydrogen(0); Semaphore oxygen(0); Void hready() { numHydrogen++; If ((numHydrogen%2 == 0) { pairofHydrogen->Signal(); } Oxygen->Wait(); }

  12. Making Water Void oReady() { pairofHydrogen->Wait(); makeWater(); Oxygen->Signal(); Oxygen->Signal(); }

  13. Making Water Semaphore hPresent(0); Semaphore waitForWater(0); Void hReady() { hPresent->signal(); waitForWater->wait(); } Void oReady() { hPresent->wait(); hPresent->wait(); makeWater(); waitForWater->Signal(); waitforWater->Signal(); }

  14. Cannibals and Missionaries • Problem: • Rowboats hold 3 people • Can’t carry 2 cannibals and 1 missionary in a boat • Boats only leave when full

More Related