Docstoc

20100222-OperatingSy.. - Computer Science and Engineering

Document Sample
20100222-OperatingSy.. - Computer Science and Engineering Powered By Docstoc
					CSE111: Great Ideas in
 Computer Science

         Dr. Carl Alphonce
           219 Bell Hall
  Office hours: M-F 11:00-11:50

           645-4739
     alphonce@buffalo.edu
cell phones off
      (please)




                 2
        Announcements

• Exam 1 handback
• HW3 starts tomorrow, due March 5.
• Second exam is March 17 (week
  after spring break)




                                      3
         Today’s Agenda

• Operating Systems
  – Resource contention
  – Semaphores


• Networking




                          4
          Resource contention
•   Two processes want to use same resources
•   Control access with flag
•   Test flag – is resource available
•   Set flag – mark resource as unavailable
•   Clear flag – mark resource as available
•   Test-interrupt-Test-Set-work-interrupt-Set-work




                                                      5
            Semaphore

• Use a semaphore to control access
  to critical region
• Critical region:
  – Code that may be executed by only
    one process at a time
• Semaphore can enforce mutual
  exclusion

                                        6
          How to resolve?

• Test-and-set (single instruction,
  atomic)
• Interrupt disable




                                      7
             Example: writing to a file
               semaphore is clear

• P1 and P2 both want to write to F




                                          8
             Example: writing to a file
              semaphore is set by P1

• P1 and P2 both want to write to F
• P1 tests-and-sets semaphore, and enters critical region




                                                     9
             Example: writing to a file
              semaphore is set by P1

• P1 and P2 both want to write to F
• P1 tests-and-sets semaphore, and enters critical region
• Context switch occurs




                                                    10
               Example: writing to a file
                semaphore is set by P1

•   P1 and P2 both want to write to F
•   P1 tests-and-sets semaphore, and enters critical region
•   Context switch occurs
•   P2 tests semaphore, finds it set, can’t enter critical
    region




                                                      11
             Example: writing to a file
              semaphore is set by P1

• P1 and P2 both want to write to F
• P1 tests-and-sets semaphore, and enters critical region
• Context switch occurs
• P2 tests semaphore, finds it set, can’t enter critical
  region
• Context switch occurs




                                                    12
             Example: writing to a file
              semaphore is set by P1

• P1 and P2 both want to write to F
• P1 tests-and-sets semaphore, and enters critical region
• Context switch occurs
• P2 tests semaphore, finds it set, can’t enter critical
  region
• Context switch occurs
• P1 exits critical region, clears semaphore




                                                    13
             Example: writing to a file
               semaphore is clear

• P1 and P2 both want to write to F
• P1 tests-and-sets semaphore, and enters critical region
• Context switch occurs
• P2 tests semaphore, finds it set, can’t enter critical
  region
• Context switch occurs
• P1 exits critical region, clears semaphore
• Context switch occurs




                                                    14
               Example: writing to a file
                semaphore is set by P2

•   P1 and P2 both want to write to F
•   P1 tests-and-sets semaphore, and enters critical region
•   Context switch occurs
•   P2 tests semaphore, finds it set, can’t enter critical
    region
•   Context switch occurs
•   P1 exits critical region, clears semaphore
•   Context switch occurs
•   P2 tests-and-sets semaphore, and enters critical region




                                                      15
                 Deadlock
• P1 has R1, needs R2 to finish
• P2 has R2, needs R1 to finish

• Example:
  – P1 has access to file F1, needs access to file F2
  – P2 has access to file F2, needs access to file F1
  – Neither will give up their file access…



                                                   16
     Conditions for deadlock
• There is competition for non-sharable resources

• Resources can be requested piecemeal

• Once allocated, cannot be stolen




                                                    17
         Resolving a deadlock
Remove one of three necessary conditions:

1. There is competition for non-sharable resources
   –   deadlock avoidance scheme


2. Resources can be requested piecemeal
   –   deadlock avoidance scheme


3. Once allocated, cannot be stolen
  –    deadlock detection and correction scheme

                                                  18
      1. Resource sharing

• Make unsharable resource appear
  sharable
• Deadlock avoidance
• Printer queue (spooling)




                                    19
 2. All resources must be acquired at once

• Prevents deadlock from occuring
• P1 cannot hold only R1 if R2 is not available.
• P2 can come along and get both R1 and R2.




                                                   20
       3. Resource stealing

• Retrieve previously allocated
  resource
• Deadlock resolution
  – Let deadlock occur
  – Resolve deadlock after the fact




                                      21
               Networking

• What sorts of networks do we use?
  –   Wired networks (in the labs)
  –   Wireless (WIFI) networks (right now?)
  –   Wireless cell phone networks
  –   Wireless bluetooth (“personal area
      networks”)



                                              22
           Configurations
• Bus network
  – Devices connected to a common
    communications channel
  – Devices are peers
  – Ex. Typical wired network
• Star network
  – Devices connected to a central machine
  – Devices communicate only via central
    machine
  – Ex. Typical wifi network (access point)
                                              23

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:5/19/2013
language:Unknown
pages:23
yan tingting yan tingting
About