Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739

Similar presentations


Presentation on theme: "CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739"— 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) 2

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

4 Today’s Agenda Operating Systems –Resource contention –Semaphores Networking 4

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 5

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 6

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

8 Example: writing to a file semaphore is clear P1 and P2 both want to write to F 8

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 9

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 10

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 11

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 12

13 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

14 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

15 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

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

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

18 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

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

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

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

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

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


Download ppt "CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739"

Similar presentations


Ads by Google