1 / 14

Suggested Exercises 5

Suggested Exercises 5. Question #1. Find a creative/funny example of synchronization that can demonstrate the difficulty of developing a monitor-based solution (in pseudocode) similar to the “Readers-Writers.”

Télécharger la présentation

Suggested Exercises 5

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. Suggested Exercises 5

  2. Question #1 • Find a creative/funny example of synchronization that can demonstrate the difficulty of developing a monitor-based solution (in pseudocode) similar to the “Readers-Writers.” • Make sure that you vigorously discuss the correctness and pitfalls of your solution.

  3. Gas Station Problem • There is a common price for gas • Consumers never modify the price – they just pump gas • Owners read modify the price • We want one owner at a time, but many consumers at the same time

  4. Developing the Solution • Global states: activeConsumers = 0; activeOwners = 0; waitingConsumers = 0; waitingOwners = 0; Condition okToPump = NULL; Condition okToChangePrice = NULL; Lock lock = FREE;

  5. Sample Code Solution – up to you to prove correctness Consumer() { lock.Acquire(); while (activeOwners > 0 || waitingOwners > 0) { ++waitingConsumers; okToPump.Wait(&lock); --waitingConsumers; } ++activeConsumers; lock.Release(); // access price and pumps lock.Acquire(); --activeConsumers; if (activeConsumers == 0 && waitingOwners > 0) { okToChangePrice.Signal(&lock); } lock.Release(); } Writer() { lock.Acquire(); while (activeOwners > 0 || activeConsumers > 0) { ++waitingOwners; okToChangePrice.Wait(&lock); --waitingOwners; } ++activeOwners; lock.Release(); // access database lock.Acquire(); --activeOwners; if (waitingOwners > 0) { okToChangePrice.Signal(&lock); } else if (waitingConsumers > 0) { okToPump.Broadcast(&lock); } lock.Release(); }

  6. Question #2 • Find a creative/funny example of deadlock, and apply various deadlock prevention approaches to the live example. • Describe the advantages and disadvantages of each approach.

  7. A Tale of Two Fisherman • Two fisherman are out fishing, but between them they only have one fishing pole and one bait. • If one takes the pole, and the other takes the bait… • They deadlock!

  8. Solutions • Infinite resources • Buy more poles and bait • No sharing • They each have their own poles and bait, fish alone • Allocate all resources at the beginning • They each either get both things or none

  9. Solutions • Allocate all resources at the beginning • They each either get both things or none semaphore pole= 1 semaphore bait= 1 lock = 1; fisher(int j) { while (TRUE) { P(s); P(pole); P(bait); // fish V(bait); V(pole); V(s); } }

  10. Solutions • Make everyone use the same ordering • Fisherman 1 goes first, then fisherman 2 (round robin)

  11. Question #3 • Please summarize the steps to configuring, compiling, and installing a kernel and its modules. • Include the step of rebooting into the new kernel.

  12. Kernel Steps • Configuring a kernel • Download kernel source • Build new configuration • Make the default configuration (smaller than the distro configuration) • Issue ‘make defconfig’ • Customize your kernel • Issue ‘make menuconfig’ and select/de-select options as you see fit

  13. Kernel Steps • Compiling a kernel • cd into kernel source, type ‘make’

  14. Kernel Steps • Installing a kernel • cd into kernel source • Issue ‘make modules_install’ to copy the modules to installation location for new kernel • Issue ‘make install’ to install the kernel executable to /boot • Make an initrd image • Issue ‘makeinitramfs –o [output file] [kernel version] • Update the boot loader • Issue ‘update-grub’, make sure grub finds both kernel image and initrd image • Reboot!

More Related