project 2 discussion n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Project 2 Discussion PowerPoint Presentation
Download Presentation
Project 2 Discussion

Loading in 2 Seconds...

play fullscreen
1 / 14

Project 2 Discussion - PowerPoint PPT Presentation


  • 106 Views
  • Uploaded on

Project 2 Discussion. Bryce Boe 2011/04/ 26 and 2011/04/29. Project 2 Overview. Semaphores Semaphore Service in Minix Pizza Synchronization Problem. Semaphore. What is a semaphore?

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Project 2 Discussion' - clara


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
project 2 discussion

Project 2 Discussion

Bryce Boe

2011/04/26 and 2011/04/29

project 2 overview
Project 2 Overview
  • Semaphores
  • Semaphore Service in Minix
  • Pizza Synchronization Problem

Bryce Boe – CS170 S11

semaphore
Semaphore
  • What is a semaphore?
    • “A semaphore is a data structure that is useful for solving a variety of synchronization problems” Downey, The Little Book of Semaphores
  • Types of synchronization problems
    • Serialization: A must occur before B
    • Mutual Exclusion: A and B cannot happen concurrently

Bryce Boe – CS170 S11

more on semaphores
More on Semaphores
  • Like an integer but…
    • Can be initialized to any value and then restricted to two main operations operations
    • Incremented -- V(), up()
    • Decremented – P(), down()
  • Why P and V?
    • Initials of Dutch words verhogen (increase) and the portmanteau prolaag [probeerteverlagen] (try to reduce)

Bryce Boe – CS170 S11

adding semaphores to minix
Adding Semaphores to Minix
  • Implemented as a service
    • Needs tocallsef_startup on initialization
    • Calls sef_receive_status to retrieve messages
    • The service requires the appropriate permissions (/etc/system.conf) to send/receive messages from other processes
  • User-level interface needs to construct messages to pass to the service
    • Use minix_rs_lookup to find the dynamic service endpoint

Bryce Boe – CS170 S11

semaphore interface
Semaphore Interface
  • intsem_init(int value)
    • Initializes new semaphore to value and returns the lowest available semaphore number >= 0
  • intsem_up(intsem_num)
    • If no one is waiting, increases the semaphore value
    • otherwise “wakes up” a the oldest waiting process

Bryce Boe – CS170 S11

semaphore interface cont
Semaphore Interface cont.
  • intsem_down(intsem_num)
    • Decreases the semaphore value
    • If the semaphore value <= 0 “sleep” the requesting process
  • intsem_release(intsem_num)
    • If no one is waiting, free the semaphore so that it can be re-used
    • Otherwise return EINUSE error (need to define in errno.h)

Bryce Boe – CS170 S11

error handling
Error Handling
  • If an invalid value is passed anywhere EINVAL should be returned to the user
  • If any functions return an error, the errno corresponding to that error should be returned
    • Such as: malloc, minix_rs_lookup

Bryce Boe – CS170 S11

semaphore pizza challenge
Semaphore (Pizza) Challenge
  • 6 grads, 2 ugrads, 2 tables with pizza
  • Only 1 student can eat at a table at a time
  • Student can only enter room if table is available
  • Grads have priority
    • 1 ugrad is eating and 1 grad comes in, the ugrad must least
    • 1 grad is eating, no ugrad can enter

Bryce Boe – CS170 S11

semaphore challenge cont
Semaphore Challenge cont.
  • Write two programs
    • grad.c – manage the 6 graduate students
    • ugrad.c – manage the 2 undergraduate students
  • Use semaphores to correctly manage the consumption of pizza
  • Solution cannot cause starvation
  • Explain your solution in pizza.txt

Bryce Boe – CS170 S11

semaphore challenge questions
Semaphore Challenge Questions
  • How can you dynamically share semaphore numbers between processes?
  • How do you determine how often the students want to eat, and for how long they eat?

Bryce Boe – CS170 S11

suggested implementation order
Suggested Implementation Order
  • Create skeleton server sema
  • Load and unload sema server via
    • service up /usr/sbin/sema
    • service down sema
  • Complete sema service
  • Complete semaphore “pizza” challenge
  • Ensure patch builds everything by running “make world” and your service starts up after a reboot

Bryce Boe – CS170 S11

implementation notes
Implementation Notes
  • Copy sched service in servers/ to sema
  • Update etc/systems.conf to add sched service (see man systems.conf if needed)
  • Add constants to include/minix/com.h
  • Add appropriate rc file to start semaphore server
  • Under /usr/src
    • make includes (updates include files)
    • make libraries (builds and updates libraries)
    • make etcforce (updates etc files)
    • make –C servers install (builds all servers)

Bryce Boe – CS170 S11

resources
Resources
  • The Little Book of Semaphores
    • http://greenteapress.com/semaphores/downey08semaphores.pdf
  • Driver programming in Minix
    • http://wiki.minix3.org/en/DevelopersGuide/DriverProgramming
    • Similar setup process

Bryce Boe – CS170 S11