Download presentation
Presentation is loading. Please wait.
Published byGervase Harper Modified over 6 years ago
1
FAA FAA (int s, int val) { temp = s; s = s + val; return temp; }
פתרון לבעיית מניעה הדדית: Shared: int s Initially: s = 1 עבור כל תהליך: Enter: while (FAA(s,-1) != 1) FAA(s,1); <CS> Exit:
2
FAA – cont. האם האלגוריתם מספק מניעה הדדית? לכל היותר תהליך יחיד ב- CS. האם האלגוריתם מספק את תנאי ההתקדמות – progress? אם pi בכניסה ואין תהליך ב- CS אזי התהליך יכנס ל- CS. האם האלגוריתם מספק הוגנות – fairness? בהנחה שאף תהליך לא נשאר זמן אין סופי ב- CS אזי כל תהליך שמבקש להיכנס יכנס בסופו של דבר.
3
FAA – cont. אלגוריתם שמקיים את 3 הדרישות: (עקרון מספר במשרד הפנים)
Shared: int s int current_ticket; Initially: s = 0; current_ticket = 0; Enter: my_ticket = FAA(s,1); while (current_ticket < my_ticket); <CS> Exit: current_ticket = my_ticket + 1;
4
Introduction to Deadlocks
Formal definition : A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause Usually the event is release of a currently held resource None of the processes can … run release resources be awakened
5
Four Conditions for Deadlock
Mutual exclusion condition each resource assigned to 1 process or is available Hold and wait condition process holding resources can request additional No preemption condition previously granted resources cannot forcibly taken away Circular wait condition must be a circular chain of 2 or more processes each is waiting for resource held by next member of the chain
6
Deadlock Modeling (3) Strategies for dealing with Deadlocks
just ignore the problem altogether detection and recovery dynamic avoidance careful resource allocation prevention negating one of the four necessary conditions
7
detection and recovery
המטרה מציאת מעגלים - אלגוריתם: For each node, N in the graph, perform the following 5 steps with N as the starting node. Initialize L to the empty list, and designate all arcs as unmarked. Add the current node to the end of L and check to see if the node now appears in L two times. If it does, the graph contains a cycle (listed in L) and the algorithm terminates. From the given node, see if there any unmarked outgoing arcs. If so, go to step 5; if not, go to step 6. Pick an unmarked outgoing arc at random and mark it. Then follow it to the new current node and go to step 3. We have now reached a dead end. Remove it and go back to the previous node, that is, the one that was current just before this one, make that one the current node, and go to step 3. If this node is the initial node, the graph does not contain any cycles and the algorithm terminates.
8
Banker's Algorithm for Multiple Resources
Example of banker's algorithm with multiple resources
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.