230 likes | 359 Views
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).
E N D
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)
Today’s Agenda • Operating Systems • Resource contention • Semaphores • Networking
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
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
How to resolve? • Test-and-set (single instruction, atomic) • Interrupt disable
Example: writing to a filesemaphore is clear • P1 and P2 both want to write to F
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
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
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
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
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
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
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
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…
Conditions for deadlock • There is competition for non-sharable resources • Resources can be requested piecemeal • Once allocated, cannot be stolen
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
1. Resource sharing • Make unsharable resource appear sharable • Deadlock avoidance • Printer queue (spooling)
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.
3. Resource stealing • Retrieve previously allocated resource • Deadlock resolution • Let deadlock occur • Resolve deadlock after the fact
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”)
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)