1 of 50

עצים בינארים

צביקה ברגר

רקורסיות

צביקה ברגר

מערכות הפעלה

Deadlock

צביקה ברגר

בס"ד

2 of 50

בס"ד

3 of 50

Deadlock Characterization

  • Mutual exclusion: only one process at a time can use (an instance of) a resource
  • Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes
  • No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task
  • Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such that:�P0 is waiting for a resource that is held by P1, �P1 is waiting for a resource that is held by P2, …, �Pn–1 is waiting for a resource that is held by Pn, �and Pn is waiting for a resource that is held by P0.

Deadlock can arise if four conditions hold simultaneously.

מדיניות

מצב ספציפי

בס"ד

4 of 50

Methods for Handling Deadlocks

  • מניעה – נבטיח שהמערכת לעולם לא תיכנס למצב של deadlock
    • תקיפת ארבעת התנאים ל- deadlock
    • שמירת המערכת מכניסה ל- deadlock

  • התאוששות – לא נמנע מהמערכת להיכנס למצב deadlock, ולכשנזהה מצב כזה נתאושש ממנו

  • התעלמות – נתעלם מהאפשרות שהמערכת עלולה להיכנס למצב של deadlock (לדוגמה ב- Unix)�

בס"ד

5 of 50

מניעה - Deadlock Prevention

  • Mutual Exclusionnot required for sharable resources (e.g., read-only files); must hold for non-sharable resources
  • Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources
    • Many solutions, e.g.:
      • Require process to request and be allocated all its resources before it begins execution
      • Allow process to request resources only when the process has none allocated to it.
    • Low resource utilization; starvation possible

גישה ראשונה – הגבלת הצורה שבה תהליכים מבקשים משאבים:

בס"ד

6 of 50

Deadlock Prevention (Cont.)

  • No Preemption
    • If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released
    • Preempted resources are added to the list of resources for which the process is waiting
    • Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting
  • Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration

בס"ד

7 of 50

Deadlock Avoidance

  • Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need
  • The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition
  • Resource-allocation state is defined by: (a) the number of available resources (b) the number of allocated resources, and (c) the maximum demands of the processes

גישה שניה – שמירה על המערכת מפני כניסה למצב של deadlock (לאורך פעולתה)

מחייב שלמערכת מידע נוסף לגבי התהליכים שרצים

בס"ד

8 of 50

Dining Philosophers Problem

בס"ד

9 of 50

Dining Philosophers Problem

בס"ד

10 of 50

Dining Philosophers Problem

בס"ד

11 of 50

בס"ד

12 of 50

LCA

בס"ד

בס"ד

Question 1

13 of 50

2020 מועד א

בס"ד

14 of 50

פתרון

בס"ד

15 of 50

פתרון

בס"ד

16 of 50

פתרון

בס"ד

17 of 50

LCA

בס"ד

בס"ד

Question 2

18 of 50

2019 מועד א

בס"ד

19 of 50

פתרון

בס"ד

20 of 50

LCA

בס"ד

בס"ד

Question 3

21 of 50

2021 מועד ב

בס"ד

22 of 50

פתרון

בס"ד

23 of 50

2019 מועד ב

בס"ד

24 of 50

פתרון

בס"ד

25 of 50

LCA

בס"ד

בס"ד

Question 4

26 of 50

מועד א 2021

בס"ד

27 of 50

פתרון

בס"ד

28 of 50

LCA

בס"ד

בס"ד

Question 5

29 of 50

2018 מועד ב

בס"ד

30 of 50

פתרון

בס"ד

31 of 50

LCA

בס"ד

בס"ד

Question 6

32 of 50

מועד ב 2022

בס"ד

33 of 50

פתרון

בס"ד

34 of 50

מועד ב 2022

בס"ד

35 of 50

פתרון

בס"ד

36 of 50

מועד ב 2022

בס"ד

37 of 50

פתרון

בס"ד

38 of 50

מועד ב 2022

בס"ד

39 of 50

פתרו

בס"ד

40 of 50

LCA

בס"ד

בס"ד

Question 7

41 of 50

מבחן 2020 מועד א

בס"ד

42 of 50

פתרון

בס"ד

43 of 50

LCA

בס"ד

בס"ד

Question 8

44 of 50

2022 מועד א

בס"ד

45 of 50

פתרון

בס"ד

46 of 50

פתרון

בס"ד

47 of 50

LCA

בס"ד

בס"ד

Question 9

48 of 50

2022 מועד ב

בס"ד

49 of 50

פתרון

בס"ד

50 of 50

LCA

בס"ד

בס"ד

שאלות?