1 / 23

CSE111: Great Ideas in Computer Science

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). Announcements. Exam 1 handback HW3 starts tomorrow, due March 5. Second exam is March 17 (week after spring break).

ilario
Download Presentation

CSE111: Great Ideas in Computer Science

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. 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

  2. cell phones off (please)

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

  4. Today’s Agenda • Operating Systems • Resource contention • Semaphores • Networking

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

  6. 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

  7. How to resolve? • Test-and-set (single instruction, atomic) • Interrupt disable

  8. Example: writing to a filesemaphore is clear • P1 and P2 both want to write to F

  9. Example: writing to a filesemaphore is set by P1 • P1 and P2 both want to write to F • P1 tests-and-sets semaphore, and enters critical region

  10. Example: writing to a filesemaphore 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

  11. Example: writing to a filesemaphore 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

  12. Example: writing to a filesemaphore 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

  13. Example: writing to a filesemaphore 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

  14. Example: writing to a filesemaphore 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

  15. Example: writing to a filesemaphore 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

  16. 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…

  17. Conditions for deadlock • There is competition for non-sharable resources • Resources can be requested piecemeal • Once allocated, cannot be stolen

  18. Resolving a deadlock Remove one of three necessary conditions: • There is competition for non-sharable resources • deadlock avoidance scheme • Resources can be requested piecemeal • deadlock avoidance scheme • Once allocated, cannot be stolen • deadlock detection and correction scheme

  19. 1. Resource sharing • Make unsharable resource appear sharable • Deadlock avoidance • Printer queue (spooling)

  20. 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.

  21. 3. Resource stealing • Retrieve previously allocated resource • Deadlock resolution • Let deadlock occur • Resolve deadlock after the fact

  22. 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”)

  23. 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)

More Related