Download presentation
Presentation is loading. Please wait.
Published byAnastasia Ramsey Modified over 9 years ago
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 1.Infinite resources – Buy more poles and bait 2.No sharing – They each have their own poles and bait, fish alone 3.Allocate all resources at the beginning – They each either get both things or none
9
Solutions 3.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 4.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 from old configuration Copy old configuration into kernel source Issue ‘make oldconfig’ – 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!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.